Free Support Forum - aspose.com

Aspose Word - List Number Restart\Continue control

Hi.

I'm trying to have control over the list numbering, for example restarting or continuing the numbering. I'm currently have a handle on the target paragraph and its ListFormat object which I want to apply the numbering restart. Do you have any methods on the ListFormat class which allows this operation?

I'm using Aspose.Words version 11.11.0.0

Many thanks

Russell

Hi Russell,


Thanks for your inquiry. If you need to reset numbering in list you should reset list. For example, the in.doc document contains 10 list items of the same list and we need to reset numbering from 5th element. Here is code to achieve this:

//Open document

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

//The document contains 10 paragraphs (list items)

//Get first paragraph (first list item)

Paragraph firstItem = doc.FirstSection.Body.FirstParagraph;

//Create copy of list

List listCopy = doc.Lists.AddCopy(firstItem.ListFormat.List);

//Get 5th element

Paragraph item = doc.FirstSection.Body.Paragraphs[4];

while (item.IsListItem)

{

item.ListFormat.List = listCopy;

item = item.NextSibling as Paragraph;

if (item == null)

break;

}

//save output document

doc.Save(@"C:\Temp\out.docx");


Moreover, I have attached the sample documents here for your reference.

Best regards,