【问题标题】:Nested Bulleted lists in Novacode docxNovacode docx 中的嵌套项目符号列表
【发布时间】:2017-07-09 13:24:40
【问题描述】:

如何使用 Novacode for docx 创建嵌套的项目符号/有序列表? 我做了一些研究,但找不到任何东西,感谢任何帮助。

【问题讨论】:

    标签: docx nested-lists novacode-docx


    【解决方案1】:

    希望还不算太晚,我几个小时前才弄明白

    class Program
    {
        static void Main(string[] args)
        {
            string docPath = "PATH TO YOUR OUTPUT WORD DOCUMENT" ;
    
            var doc = DocX.Create(docPath);
            var l = doc.AddList("Item #1", 0, ListItemType.Bulleted, 0);
            doc.AddListItem(l, "Item #2");
            doc.InsertList(l);
    
            doc.Save();
        }
    }
    

    【讨论】:

    • 感谢您的回复。但是这里看不到嵌套列表,AddList 创建一个列表,addlistItem 将项目添加到创建的列表中,然后 insertlist 将其添加到文档中,不是吗?
    【解决方案2】:

    您应该使用缩进级别(DocX.AddList(...) 的参数 2 和 DocX.AddListItem(...) 的参数 3)

    DocX doc = DocX.Create("filename.docx");
    
    List list = doc.AddList("item 1", 0, ListItemType.Numbered);
    doc.AddListItem(list, "item 2", 1);
    doc.AddListItem(list, "item 3", 1);
    doc.AddListItem(list, "item 4", 2);
    doc.AddListItem(list, "item 5", 2);
    doc.AddListItem(list, "item 6", 1);
    doc.AddListItem(list, "item 7", 0);
    doc.AddListItem(list, "item 8", 2);
    
    doc.InsertList(list);
    

    这会产生:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2016-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多