Paragraphs with "numbering" don't respond to "style"
See original GitHub issueParagraphs with numbering
defined do not respond to style
in 5.0.0
. See the example below, followed by the code that generated it.
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:
- Created 4 years ago
- Reactions:6
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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