gpt4 book ai didi

C# DocX : Inserting new numbered list continues numbering

转载 作者:行者123 更新时间:2023-11-30 16:09:03 25 4
gpt4 key购买 nike

我正在尝试使用 Novacode DocX 将几个编号列表插入到 Word 文档中。

像这样:

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);

这会产生这个:

  1. 1 号
  2. 2 号
  3. 1 号
  4. 2 号

我期望的是:

  1. 1 号
  2. 2 号
  1. 1 号
  2. 2 号

好像是startNumber参数不起作用。在生成的文档的 numbering.xml 文件中,我可以看到 numIds 和 abstractNumIds 似乎都已正确生成。两个列表有不同的numIds,分别引用不同的abstractNumIds。

任何人都知道可能是什么问题(除了 DocX 库中的错误)?我在 Word 2010 中打开文档,所以我的一个理论是与 DocX 和 Word > 2007 存在一些不兼容。如果是这种情况,我可能必须在生成文档后对 XML 做一些事情..

最佳答案

原来是 Novacode.Docx 中的一个错误。我为它提交了一个补丁,在 1.0.0.16 版本中应用

关于C# DocX : Inserting new numbered list continues numbering,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28213830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com