in demo 3, we are expected to have nested list with indexing types of:
"upperRoman" -> "decimal" -> "lowerLetter".
const abstractNum = numbering.createAbstractNumbering();
abstractNum.createLevel(0, "upperRoman", "%1", "start")
.addParagraphProperty(new docx.Indent(720, 260));
abstractNum.createLevel(1, "decimal", "%2.", "start")
.addParagraphProperty(new docx.Indent(1440, 980));
abstractNum.createLevel(2, "lowerLetter", "%3)", "start")
.addParagraphProperty(new docx.Indent(2160, 1700));
But in practice we get nested list of all decimals.
Document-3.docx
interesting, yeah that is a problem
@amitm02 The docs were a little messed up but I was able to get it work by doing this:
const docx = require("docx");
const { Document, Paragraph, Packer, Numbering, Indent } = docx;
const doc = new Document();
const numbering = doc.Numbering;
const abstractNum = numbering.createAbstractNumbering();
abstractNum
.createLevel(0, "upperRoman", "%1", "left")
.addParagraphProperty(new Indent({ left: 720, hanging: 260 }));
abstractNum
.createLevel(1, "decimal", "%2.", "left")
.addParagraphProperty(new Indent({ left: 1440, hanging: 260 }));
abstractNum
.createLevel(2, "lowerLetter", "%3)", "left")
.addParagraphProperty(new Indent({ left: 2160, hanging: 260 }));
const concrete = numbering.createConcreteNumbering(abstractNum);
const topLevelP = new Paragraph("Hey you");
const subP = new Paragraph("What's up fam");
const secondSubP = new Paragraph("Hello World 2");
const subSubP = new Paragraph("Yeah boi");
topLevelP.setNumbering(concrete, 0);
subP.setNumbering(concrete, 1);
secondSubP.setNumbering(concrete, 1);
subSubP.setNumbering(concrete, 2);
doc.addParagraph(topLevelP);
doc.addParagraph(subP);
doc.addParagraph(secondSubP);
doc.addParagraph(subSubP);
const packer = new Packer(doc, undefined, undefined, numbering);
I hope this helps you out!
const packer = new Packer(doc, undefined, undefined, numbering);
on v4.7.1, packer doesn't need argument
Think the problem is in the documentation as it shows creating Numbering like
const doc = new Document();
const numbering = new Numbering();
that doesn't seem to work whereas the following does
const doc = new Document();
const numbering = doc.Numbering;
This is fixed now
Now the document has it's own instance of Numbering, so you don't need to "new" up a new Numbering, which I think was the source of the error and confusion
Most helpful comment
@amitm02 The docs were a little messed up but I was able to get it work by doing this:
I hope this helps you out!