C# DocX: Inserting new numbered list continues numbering

倾然丶 夕夏残阳落幕 提交于 2019-12-23 19:08:12

问题


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:

  1. Number 1
  2. Number 2
  3. Number 1
  4. Number 2

What I expect is this:

  1. Number 1
  2. Number 2
  1. Number 1
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!