How to set Custom List Level Style using Java

Hello,
I would like to apply my own numbering style for a paragraph, which has the Header (1, …, 9) style
unfortunately, nothing appears in the resulting file.
Code:

    private static void insertListLvlFormatTest(){
        try {
            Document doc = new Document();
            doc.removeAllChildren();
            Section section = new Section(doc);
            doc.appendChild(section);
            DocumentBuilder documentBuilder = new DocumentBuilder(doc);

            Shape box = new Shape(doc, ShapeType.TEXT_BOX);
            box.setWidth(153);
            box.setHeight(150.0);
            box.setWrapType(WrapType.NONE);
            box.setTop(50);
            box.setLeft(100);
            box.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
            box.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
            box.appendChild(new Paragraph(documentBuilder.getDocument()));
            documentBuilder.insertNode(box);

            final Paragraph lastParagraph = box.getLastParagraph();
            lastParagraph.appendChild(new Run(doc, "Paragraph test"));
            lastParagraph.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_3);

            com.aspose.words.List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
            ListLevel levelZero = list.getListLevels().get(0);
            // format:  1.2.3
            final String format = Stream.of("1", "2", "3")
                    .map(s -> String.valueOf(Character.toChars(Integer.parseInt("000" + s, 16))))
                    .collect(Collectors.joining("."));
            levelZero.setAlignment(ListLevelAlignment.LEFT);
            levelZero.setNumberStyle(NumberStyle.ARABIC);
            levelZero.setNumberFormat(format);// \u0001 also do not work
            levelZero.setTrailingCharacter(ListTrailingCharacter.SPACE);
            lastParagraph.getListFormat().setList(list);


            OoxmlSaveOptions options = new OoxmlSaveOptions();
            options.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);
            documentBuilder.getDocument()
                    .save(System.getProperty("user.dir") + File.separator + "List_test_"+System.currentTimeMillis()+".docx", options);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

@aolo23

Please set the list number format as shown below to get the desired output. Hope this helps you.

com.aspose.words.List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
list.getListLevels().get(0).setNumberFormat("\u0000.");
list.getListLevels().get(1).setNumberFormat("\u0000.\u0001");
list.getListLevels().get(2).setNumberFormat("\u0000.\u0001.\u0002");
list.getListLevels().get(3).setNumberFormat("\u0000.\u0001.\u0002.\u0003");
1 Like