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

Free Support Forum - aspose.com

Apply Custom Styles to Multi-Level List


I'm basing a new document on a Word template that has custom styles defined for different levels within a multi-level list.

To insert the multi-level list data into the document I loop through the collections and set the appropriate custom list style for the level of the list. When the document is created my list has no formatting. How can I do this? Below is my current code:

foreach (var module in modules)
builder.ParagraphFormat.StyleName = "MyCustomLevel1";

foreach (var location in module.Locations)
builder.ParagraphFormat.StyleName = "MyCustomLevel2";

foreach (var item in location.Items)
builder.ParagraphFormat.StyleName = "MyCustomLevel3";

Hi Walter,

Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Hello Tahir.

Attached is a copy of the template with a sample of what the actual list is supposed to look like. Below that I list the name of each style that is used to format each level and these custom styles are in this template.

Thank you for the assistance.

Hi Walter,

Thanks for sharing the detail. Please use the ParagraphFormat.ClearFormatting method before applying the custom styles. This will solve your issue. Please let us know if you have any more queries.

Document doc = new
Document(MyDir + “AsposeSampleTemplate.dotx”);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

Paragraph para = doc.FirstSection.Body.Paragraphs[doc.FirstSection.Body.Paragraphs.Count - 4];


para.ParagraphFormat.Style = doc.Styles["PIP SubSection Header"];



Style style = doc.Styles["PIP Outline Section"];

Style style1 = doc.Styles["PIP SubSection Header"];

builder.ParagraphFormat.Style = style;

builder.Writeln("Text with PIP Outline Section style");

builder.ParagraphFormat.Style = style1;

builder.Writeln("Text with PIP SubSection Header style");

doc.Save(MyDir + "Out.docx");

Thank you very much for your help, it works great now!

Hi Walter,

Thanks for your feedback. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.