Auto numbering headings

Hey there,

I have a question the auto-nummerate functionality of Aspose Words Java.
I would like to insert some headings into the word document with numbers over several heading levels like this:

  1. Heading
    1.1. Heading
  2. Heading
    2.1. Heading
    2.1.1 Heading

or like these document.
Test.zip (10.4 KB)

Best regards,

Paul Bachmann

@B4chi,

Thanks for your inquiry. Please use the following code example to create the nested list. Hope this helps you.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.ListFormat.List = doc.Lists.Add(ListTemplate.NumberDefault);
builder.ListFormat.ListLevel.Font.Bold = true;
builder.ListFormat.ListLevel.Font.Color = Color.Red;
builder.Writeln("Main Section1");

builder.ListFormat.ListIndent();
builder.ListFormat.ListLevel.Font.Italic = true;
builder.ListFormat.ListLevel.Font.Color = Color.Green;
builder.ListFormat.ListLevel.NumberStyle = NumberStyle.Arabic;
builder.ListFormat.ListLevel.NumberFormat = "\x0000.\x0001";
builder.Writeln("Sub Section1.1 ");

builder.ListFormat.ListIndent();
builder.ListFormat.ListLevel.Font.Underline = Underline.Dash;
builder.ListFormat.ListLevel.Font.Color = Color.Blue;
builder.ListFormat.ListLevel.NumberStyle = NumberStyle.Arabic;

builder.ListFormat.ListLevel.NumberFormat = "\x0000.\x0001.\x0002";

builder.Writeln("Sub Section 1.1.1");

builder.ListFormat.ListOutdent();
builder.Writeln("Sub Section 1.2 ");

builder.ListFormat.ListOutdent();

builder.Writeln("Main Section2");

builder.ListFormat.ListIndent();

builder.Writeln("Sub Section2.1");
                 
builder.ListFormat.RemoveNumbers();

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

Thank you for your fast reply.
It was very helpful for me and I could solve my problem.