We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Formatting of Lists

Greetings. Using the Words component I am trying to apply a style to all lists within a document, however I can't seem to figure out how to successfully do this. I believe I am missing overlooking something that is easy. The following code describes what I am attempting. Can someone please let me know what I should write in the "***what code should go here" portion of the foreach loop to apply the defined style to each list in the document? Many thanks.

List listStyle = doc.Styles.Add(StyleType.List, "MyListStyle");
//style properties omitted

Lists myInsertedlists = doc.Lists;
foreach (List singleList in myInsertedlists) {
*** what code should go here?


Thanks for your inquiry. Unfortunately you can’t apply the defined style to each list in the document. I have created a new issue # 4586 in our defect database.

As workaround you can try using the following code.

// Create a list style.

Style listStyle = doc.Styles.Add(StyleType.List, "MyListStyle");

// Create a list based on the list style.

List myList = doc.Lists.Add(listStyle);

// Apply the list to all bulleted and numbered paragraphs.

// This code might not be enough for you if you have numbered lists in the document

// as all paragraphs will belong to the same list and have sequential numbering.

// If this code is not enough for you, it has to be slightly extended. You will need to

// add a hashtable and create a new list instance based on a list style for each old list instance.

// The hashtable key will be old list instance and the value will be the new list instance.

// Let me know if you need help on that.

ParagraphCollection paras = doc.GetChildNodes(NodeType.Paragraph, true, false);

foreach (Paragraph para in paras)


if (para.IsListItem)


Para.ListFormat.List = myList;



I hope this could help you.

Best regards.