Skip numbering on word headings

Hello there

I have a problem with Aspose.Words. I need to skip the numbering of a certain heading.
For example:
1 Heading 1
2 Heading 2
2.1 Heading 2.1
2.2 Heading 2.2

Need to become
1 Heading 1
3 Heading 2
3.1 Heading 2.1
3.2 Heading 2.2

I need to set the numbering value.
Is there any way to do this?

@ImTryingOkay,
Please check the following code example, showing how to get the desired output for a list:

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

Paragraph paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 1, true);
if (paragraph.IsListItem)
{
    Aspose.Words.Lists.List newlist = doc.Lists.AddCopy(paragraph.ListFormat.List);
    while (paragraph != null && paragraph.IsListItem)
    {
        paragraph.ListFormat.List = newlist;
        paragraph = (Paragraph)paragraph.NextSibling;
    }
}
Aspose.Words.Lists.List list = doc.Lists[1];
list.ListLevels[0].StartAt = 3;

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

The idea is to create a new list for items, starting from the second item, and to set the ListLevels[0].StartAt property for this list to 3.

Please also check the input file “skipNum.docx”, used to test the code example bellow:

1 Like

Thanks thats what im looking for.
Now I dont always have to skip the same heading,
Do you per chance know a way to iterate through only say the styles of heading 1?

@ImTryingOkay,
You can use the following code example to iterate through all paragraphs with “Heading 1” style applied on them:

foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
    if (p.ParagraphFormat.Style.Name == "Heading 1")
        Console.WriteLine(p.GetText());