question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Paragraphs with "numbering" don't respond to "style"

See original GitHub issue

Paragraphs with numbering defined do not respond to style in 5.0.0. See the example below, followed by the code that generated it.

image

Code:

var fs = require('fs')
var docx = require('docx');

const doc = new docx.Document();

doc.Styles.createParagraphStyle("numberdemo", "Number Demo")
	.basedOn("Normal")
	.next("Normal")
	.font("Arial")
	.quickFormat()
	.size(40);

const numbering = new docx.Numbering();

const abstractNum = numbering.createAbstractNumbering();

abstractNum.createLevel(0, "upperRoman", "%1", "start").indent({ left: 360, hanging: 130 });
abstractNum.createLevel(1, "decimal", "%1.%2.", "start").indent({ left: 1200, hanging: 3000 });
abstractNum.createLevel(2, "lowerLetter", "%3)", "start").indent({ left: 4000, hanging: 5000 });

const concrete = numbering.createConcreteNumbering(abstractNum);

doc.addSection({
	children: [
		new docx.Paragraph({ text: "No numbering", style: "numberdemo" }),
		new docx.Paragraph({ text: "No numbering, no style" }),
		new docx.Paragraph({ text: "Item 1", numbering: { num: concrete, level: 0 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "Item 1.1", numbering: { num: concrete, level: 1 }}),
		new docx.Paragraph({ text: "Item 1.2", numbering: { num: concrete, level: 1 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "Item 1.2.1", numbering: { num: concrete, level: 2 }}),
		new docx.Paragraph({ text: "Item 1.2.2", numbering: { num: concrete, level: 2 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "Item 1.2.3", numbering: { num: concrete, level: 2 }}),
		new docx.Paragraph({ text: "Item 1.3", numbering: { num: concrete, level: 1 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "Item 2", numbering: { num: concrete, level: 0 }}),
		new docx.Paragraph({ text: "Item 3", numbering: { num: concrete, level: 0 }, style: "numberdemo" }),
		new docx.Paragraph({ text: "No numbering 2", style: "numberdemo" }),
		new docx.Paragraph({ text: "No numbering, no style 2" })
	],
});

docx.Packer.toBuffer(doc).then((buffer) => {
	fs.writeFileSync("docx-simple-num.docx", buffer);
});

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ramonmatacommented, Oct 18, 2019

Had a similar issue, look into the code and seems you need to set the custom property to true when adding the numbering into the paragraph

numbering: {
  num: concrete,
  level: 1,
  custom: true
}
0reactions
dolanmiucommented, Mar 13, 2021

I believe this issue is now fixed

Checking demo 2, styles are applied to the numbering:

https://github.com/dolanmiu/docx/blob/master/demo/11-declaritive-styles-2.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Automatic Paragraph Numbering Back on Track
Occasionally, however, some paragraph numbers just don't respond to the Continue Numbering command. Here's what I do as a fallback position.
Read more >
Numbered paragraph styles synchronized with Heading X styles
Hallo everybody. I have a problem creating outline numbered lists bound to the corresponding Heading X styles.
Read more >
Microsoft Word Training - Styles and Automatic Paragraph ...
In this Microsoft Word live training session we show you how to apply automatic paragraph numbering to styles. Learn more about our training ......
Read more >
Numbering on New Paragraph Doesn't Work as Expected
The most likely cause of this behavior is actually a built-in feature of Word. When you define a style you can specify what...
Read more >
Solved: Numbered Paragraph Styles not working - 9234177
I have set up a good number of paragraph styles. Unfortunately, when applying these especially the numbered ones, some of the applied styles...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found