问题
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