【问题标题】:OpenXML v2 is painful. Why can't I create a bulleted list?OpenXML v2 很痛苦。为什么我不能创建项目符号列表?
【发布时间】:2013-03-12 20:11:12
【问题描述】:

一个应该创建一个编号列表,另一个应该创建一个项目符号列表,如本网站所示

http://sharepointweblog.blogspot.com/2009/07/open-xml-insert-bullets-and-numbering.html

但两者都有编号..为什么?

另外.. 使用 openXML 以编程方式创建 word doc 似乎非常痛苦。. 是否有任何好的参考资料可以帮助解释创建基本 word doc? (一些文字,一些要点)..

Paragraph paraBullet1 = new Paragraph(
              new ParagraphProperties(
              new ParagraphStyleId() { Val = "ListParagraph" },
              new NumberingProperties(
                                      new NumberingLevelReference() { Val = 0 },
                                      new NumberingId() { Val = 1 })),
                                      new Run(new Text("List 1"))
                                      ) { RsidParagraphAddition = "005F3962", RsidParagraphProperties = "00330DA9", RsidRunAdditionDefault = "00330DA9" };

Paragraph paraTest2 = body.AppendChild(paraBullet1);

Paragraph paraBullet2 = new Paragraph(
             new ParagraphProperties(
             new ParagraphStyleId() { Val = "ListParagraph" },
             new NumberingProperties(
                                     new NumberingLevelReference() { Val = 0 },
                                     new NumberingId() { Val = 2 })),
                                     new Run(new Text("List 2"))
                                     ) { RsidParagraphAddition = "00031711", RsidParagraphProperties = "00031711", RsidRunAdditionDefault = "00031711" };

Paragraph paraTest2x = body.AppendChild(paraBullet2);

【问题讨论】:

  • 我想编号格式是在 docx 文件包内的 numbering.xml 文件中定义的。您可以使用 OpenXML SDK 2.0 Productivity Tool(您可能已随 SDK 下载)打开您的 docx 文件,反映 document.xml 的代码并尝试找到合适的样式。通过查看该文件,我建议使用 NumberFormatValues.Bullet 和 AbstractNum 元素来查找它所附加的元素。然后找到与之关联的NumberingInstance,并查看它的NumberId 属性。不过我还没有对此进行测试,因此有效 ID 可能位于不同的属性或对象中。
  • +1 表示“OpenXML 很痛苦”。我们应该成立一个支持小组。
  • 可以写一些工厂方法来简化代码。

标签: c# ms-word openxml office-2007


【解决方案1】:

从这个问题中寻找大卫耶茨的答案。他成功了。他的解决方案虽然要求你拥有不止一颗子弹,但他的助手类有效。我有同样的问题。如果您没有正确设置 numbering.xml(将您的 .doc 重命名为 .zip 并查看 xmld),则编号列表似乎是默认值。

http://stackoverflow.com/questions/1940911/openxml-2-sdk-word-document-create-bulleted-list-programmatically

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2014-08-18
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    相关资源
    最近更新 更多