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

Free Support Forum - aspose.com

我需要对多级目录进行左对齐,但是我的代码无法做对齐处理

输入文档:The paragrah OutlineLevel-new.docx (13.3 KB)

我期望的输出格式文档 output.docx (28.2 KB)

我的代码

Document doc = new Document(“The paragrah OutlineLevel-new.docx”);

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.\u0002");

    level3.isLegal(true);


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

    level4.setNumberStyle(NumberStyle.ARABIC);

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

    level4.isLegal(true);

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

    level5.setNumberStyle(NumberStyle.ARABIC);

    level5.setNumberFormat("\u0000.\u0001.\u0002.\u0003.\u0004");

    level5.isLegal(true);


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

    level6.setNumberStyle(NumberStyle.ARABIC);

    level6.setNumberFormat("\u0000.\u0001.\u0002.\u0003.\u0004.\u0005");
    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)

    {
        para.getListFormat().applyNumberDefault();
        para.getParagraphFormat().setLeftIndent(0.0d);
        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);
        }

    }


    doc.save(  "/kkk1.docx");

@garyshen,

请关注您的其他线程以进行进一步的处理。