Hello,
Is it possible to restart a numbering set on a header paragraph?
can you show a picture of a word document to what you mean?
Hello, I am having a similar issue.
Please see attached. I would like the list that starts at 5 to restart at 1.
I searched the code and I can't see any method that applies the
http://officeopenxml.com/WPnumbering-restart.php
Attached is a file created using docx that has the issue:
420bcb9a-92f8-4c11-9ca2-8549b02712e6.docx
And here is the file that has been fixed manually:
420bcb9a-92f8-4c11-9ca2-8549b02712e6_Fixed.docx
Thanks so much, ill look into this
@trzopekm, @flaglerkid I found this issue happened for me because I instantiated multiple instances of the
Numbering Class which reset the id counter (nextId) to zero each time I instantiated it.
For example the code below produces the issue:
const doc = new Document();
const makeList = (doc, items) => {
const numbering = new Numbering();
const abstractNum = numbering.createAbstractNumbering();
abstractNum.createLevel(0, "upperRoman", "%1", "start");
const concrete = numbering.createConcreteNumbering(abstractNum);
items.forEach((item)) => {
const itemPara = new Paragraph(item);
itemPara.setNumbering(concrete, 0);
doc.addParagraph(itemPara);
});
};
makeList(doc, ['a', 'b', 'c']);
doc.addParagraph(new Paragraph('Some text in between'));
makeList(doc, ['d', 'e', 'f']);
When I output to word, it gives a document with the following structure:
Some text in between
Whereas the following resolves the issue for me:
const doc = new Document();
const numbering = new Numbering();
const makeList = (doc, items) => {
const abstractNum = numbering.createAbstractNumbering();
abstractNum.createLevel(0, "upperRoman", "%1", "start");
const concrete = numbering.createConcreteNumbering(abstractNum);
items.forEach((item)) => {
const itemPara = new Paragraph(item);
itemPara.setNumbering(concrete, 0);
doc.addParagraph(itemPara);
});
};
makeList(doc, ['a', 'b', 'c']);
doc.addParagraph(new Paragraph('Some text in between'));
makeList(doc, ['d', 'e', 'f']);
When I output this to word I get this structure:
Some text in between
@dolanmiu maybe a note in the docs is all that's needed?
Ah interesting, so you moved const numbering = new Numbering(); to the top?
I will add this to the README thanks
I'll create a more intuitive way to do this in future, as now it seems odd
Yes, moving const number = new Numbering(); out of the functional scope fixed the issue.
In terms of a more intuitive way, it seems like each document should always only have one Numbering associated with it.
Perhaps having the doc class instantiate its own numbering property and exposing that property via an accessor would help in most standard cases.
Yes, moving
const number = new Numbering();out of the functional scope fixed the issue.
Now you no longer need to create a new Numbering now, as the document has one.
In terms of a more intuitive way, it seems like each document should always only have one
Numberingassociated with it.
There shouldn't be any issues now
If there is, re-open this!
Most helpful comment
Yes, moving
const number = new Numbering();out of the functional scope fixed the issue.In terms of a more intuitive way, it seems like each document should always only have one
Numberingassociated with it.Perhaps having the doc class instantiate its own numbering property and exposing that property via an accessor would help in most standard cases.