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

Free Support Forum - aspose.com

How to set IsListStyleDefinition

In documentation I see that IsListStyleDefinition style type can’t set directly.
I explaine my case. I export from docx file paragraphs as list of they html + some property style.
After that I try insert they html back to create docx file. Processing each paragraphs back, I set list style from code and had exception on set style which IsListStyleDefinition .
How I should set it?


I am afraid, List.IsListStyleDefinition is a read-only property. It returns true if this list is a definition of a list style.

Please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Aspose.Words 19.7 generated output HTML file
  • Aspose.Words 19.7 generated output DOCX file showing the undesired behavior
  • Your expected Word document showing the correct output. You can create expected document by using MS Word.
  • Please also create a simplified standalone console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

@ awais.hafeez
I expressed not quite right. There is a list format in the office document whose IsListStyleDefinition flag is true. I need to create a new paragraph in document and apply a list style to it with IsListStyleDefinition equal to true. I get an error. The question is, can I somehow apply this list format to the paragraph?


Please see these input/output documents (Docs-200520.zip (19.8 KB)) and try running the following code:

Document doc = new Document(@"E:\Temp\in.docx");

List list = doc.Lists[0];

Paragraph para = new Paragraph(doc);
para.AppendChild(new Run(doc, "Last line"));

doc.FirstSection.Body.InsertBefore(para, doc.FirstSection.Body.LastParagraph);
// Lets make this new Paragraph part of list

para.ListFormat.List = list;


Hope, this helps in achieving what you are looking for.

Before ask, I did same.

Document doc = new Document("C:\\11\\problem_list_test.docx");    
List list = doc.getLists().getListByListId(1); //list style with name outline has IsListStyleDefinition  = true
Paragraph para = new Paragraph(doc);
para.appendChild(new Run(doc, "Last line"));
doc.getFirstSection().getBody().insertAfter(para, doc.getFirstSection().getBody().getLastParagraph());
para.getListFormat().setList(list); // there are error

I attach test document problem_list_test.zip (20.8 KB)

Exception message : Exception in thread “main” java.lang.IllegalArgumentException: The list is a definition of a list style.
at com.aspose.words.ListFormat.setList(Unknown Source)


We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-19020. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.


Regarding WORDSNET-19020, I am afraid, it is not possible in current implementation to set list with “IsListStyleDefinition” flag as current list formatting for another paragraph. However, in the provided example paragraph formatted with “WWParty” style and has no other direct formatting:

    <w:pStyle w:val = "WWParty" />
</ w:pPr>

So, numbering and its level also defined with this style. You may apply “WWParty” style to new paragraph to get required result:

Document doc = new Document("E:\\Temp\\problem_list_test\\problem_list_test.docx");

Style style = doc.getFirstSection().getBody().getLastParagraph().getParagraphFormat().getStyle();

Paragraph para = new Paragraph(doc);
para.appendChild(new Run(doc, "Last line"));

doc.getFirstSection().getBody().insertAfter(para, doc.getFirstSection().getBody().getLastParagraph());
// Applied the same numbering as for previous paragraph.

If you want to set just list formatting then “Document.Lists.AddCopy” method may be used. And obtained copy should be applied to paragraphs. However, this method resets link to numbering style. So, we are not sure if that will be suitable for you.

It is actually not clear to us what exactly do you want to achieve. If the above code and Document.Lists.AddCopy method are not suitable for you then we may investigate it further based on your further input on this topic. Thanks for your cooperation.


We are waiting for your further input on this topic (WORDSNET-19020). Please see my previous post and share your feedback. Thanks for your cooperation.

awais.hafeez hi, I’ll try today your way. I am storing a document as a set of paragraphs in HTML format in a database. I need to translate individual html paragraphs into a complete document, for this I restore the styles by write code that were also saved in the paragraph database.


Yes, you can convert each Paragraph in Word document to HTML string and then save HTML in database for future use. Anyways, we will wait for your further input/feedback on this topic.


Regarding WORDSNET-19020, we have completed the work on this issue and concluded to close this issue with “Not a Bug” status. Please use the workaround mentioned in the following post.