Nested Bulleted lists in Novacode docx

落花浮王杯 提交于 2019-12-08 09:23:28

问题


How can i create nested bulleted/Ordered lists with Novacode for docx? I've done some research but couldn't find anything, any help is appreciated.


回答1:


Hope it's not too late, I've just figured it out a couple hours ago

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



回答2:


You should use the indent-level (parameter 2 of DocX.AddList(...) and parameter 3 of DocX.AddListItem(...))

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

This produces:



来源:https://stackoverflow.com/questions/42341622/nested-bulleted-lists-in-novacode-docx

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