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

Free Support Forum - aspose.com

List Level Numbers are Incorrect after setting List Level Number using Java

The original file The paragrah OutlineLevel.docx (12.6 KB)

I have individual problems with my code, please help me to check,The following is the format I want
1 The paragrah OutlineLevel.LEVEL_1 title
1.1 The paragrah OutlineLevel.LEVEL_2 title
1.1.1 The paragrah OutlineLevel.LEVEL_3 title
1.1.1.1 The paragrah OutlineLevel.LEVEL_4 title
2 The paragrah OutlineLevel.LEVEL_1 title
2.1 The paragrah OutlineLevel.LEVEL_2 title
2.2 The paragrah OutlineLevel.LEVEL_3 title
2.2.1 The paragrah OutlineLevel.LEVEL_4 title
2.2.1.1 The paragrah OutlineLevel.LEVEL_5 title

after running my code,the output result is incorrect.as below:
1.1 The paragrah OutlineLevel.LEVEL_1 title
1.1.1 The paragrah OutlineLevel.LEVEL_2 title
1.1.1 The paragrah OutlineLevel.LEVEL_3 title
1.1.1.1 The paragrah OutlineLevel.LEVEL_4 title
1.2 The paragrah OutlineLevel.LEVEL_1 title
1.2.2 The paragrah OutlineLevel.LEVEL_2 title
1.2.2 The paragrah OutlineLevel.LEVEL_3 title
1.2.2.2 The paragrah OutlineLevel.LEVEL_4 title
1.2.2.2.2 The paragrah OutlineLevel.LEVEL_5 title

My Code:

   com.aspose.words.List list = doc.getLists().add(ListTemplate.OUTLINE_LEGAL);
   ListLevel level1 = list.getListLevels().get(0);

    level1.setNumberStyle(NumberStyle.ARABIC);

    level1.setNumberFormat("\u0000");


    ListLevel level2 = list.getListLevels().get(1);

    level2.setNumberStyle(NumberStyle.ARABIC);

    level2.setNumberFormat("\u0000.\u0001");

    level2.isLegal(true);

    ListLevel level3 = list.getListLevels().get(2);

    level3.setNumberStyle(NumberStyle.ARABIC);

    level3.setNumberFormat("\u0000.\u0001.\u0001");

    level3.isLegal(true);

    ListLevel level4 = list.getListLevels().get(3);

    level4.setNumberStyle(NumberStyle.ARABIC);

    level4.setNumberFormat("\u0000.\u0001.\u0001.\u0001");

    level4.isLegal(false);

    ListLevel level5 = list.getListLevels().get(4);

    level5.setNumberStyle(NumberStyle.ARABIC);

    level5.setNumberFormat("\u0000.\u0001.\u0001.\u0001.\u0001");

    level5.isLegal(true);

    ListLevel level6 = list.getListLevels().get(5);

    level6.setNumberStyle(NumberStyle.ARABIC);

    level6.setNumberFormat("\u0000.\u0001.\u0001.\u0001.\u0001.\u0001");

    level6.isLegal(true);

    NodeCollection nodes = doc.getChildNodes(NodeType.PARAGRAPH, true);
    List<Paragraph>  paragraphs=(List<Paragraph>)StreamSupport.stream(nodes.spliterator(), false).filter(  node -> ((Paragraph)node).getParagraphFormat().getOutlineLevel() < OutlineLevel.BODY_TEXT).collect(  Collectors.toList())
    for (Paragraph para : paragraphs)

    {

        if (para.getParagraphFormat().getOutlineLevel()==OutlineLevel.LEVEL_1)

        {

            para.getListFormat().setList(list);

            para.getListFormat().setListLevelNumber(0);

        }

        else if (para.getParagraphFormat().getOutlineLevel()==OutlineLevel.LEVEL_2)

        {

            para.getListFormat().setList(list);

            para.getListFormat().setListLevelNumber(1);

        }  else if (para.getParagraphFormat().getOutlineLevel()==OutlineLevel.LEVEL_3)

        {

            para.getListFormat().setList(list);

            para.getListFormat().setListLevelNumber(2);

        }
        else if (para.getParagraphFormat().getOutlineLevel()==OutlineLevel.LEVEL_4)

        {

            para.getListFormat().setList(list);

            para.getListFormat().setListLevelNumber(3);

        }
        else if (para.getParagraphFormat().getOutlineLevel()==OutlineLevel.LEVEL_5)

        {

            para.getListFormat().setList(list);

            para.getListFormat().setListLevelNumber(4);

        }  else if (para.getParagraphFormat().getOutlineLevel()==OutlineLevel.LEVEL_6)

        {

            para.getListFormat().setList(list);

            para.getListFormat().setListLevelNumber(5);
        }

    }

thanks pls help me.

@garyshen

We have tested the scenario using the latest version of Aspose.Words for Java 21.8 and have not found the shared issue. So, please use Aspose.Words for Java 21.8.

@tahir.manzoor
Maybe my sample is not complete.there is my new sample. The paragrah OutlineLevel-new.docx (13.0 KB)

My question is if the level is the same, the serial number does not increase
my test computer is mac os,aspose word jar is for java 21.8 jdk7.
This is my new test result. as below attachment
error format .jpg (213.7 KB)

@garyshen

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.