问题
I am trying to insert several numbered lists into a Word document using Novacode DocX.
Something like this:
var doc = DocX.Create("somedoc.docx");
var list = doc.AddList(listType: ListItemType.Numbered, startNumber: 1);
doc.AddListItem(list, "Number 1", 0, listType);
doc.AddListItem(list, "Number 2", 0, listType);
doc.InsertList(list);
doc.InsertParagraph(); //just to get some space between.
var secondList= doc.AddList(listType: ListItemType.Numbered, startNumber: 1);
doc.AddListItem(secondList, "Number 1", 0, listType);
doc.AddListItem(secondList, "Number 2", 0, listType);
doc.InsertList(secondList);
This produces this:
- Number 1
- Number 2
- Number 1
- Number 2
What I expect is this:
- Number 1
- Number 2
- Number 1
- Number 2
It seems that the startNumber parameter does not work. In the resulting document's numbering.xml file, I can see that both numIds and abstractNumIds seem to be generated correctly. The two list have different numIds, each referring to different abstractNumIds.
Anyone got any idea about what might be the problem (other than a bug in the DocX library)? I am opening the document in Word 2010, so one theory I have is that there is some incompatability with DocX and Word > 2007. If that is the case, I probably have to do something with the XML after generating the document..
回答1:
Turned out to be a bug in Novacode.Docx. I submitted a patch for it that was applied in version 1.0.0.16
来源:https://stackoverflow.com/questions/28213830/c-sharp-docx-inserting-new-numbered-list-continues-numbering