How to create multiLevel bullets and numbering from java using apache POI XWPFDocument?

前端 未结 1 1566
忘掉有多难
忘掉有多难 2021-01-19 02:30

I\'ve read many blogs and forums related to my requirement, but till now I was able to generate bullet or numbering for first level with all the help I got. Can anyone guide

相关标签:
1条回答
  • 2021-01-19 03:14

    You are right Apache POI has the worst kind of documentation or you can say no documentation at all. So there is nothing much you can find except a few blogs.

    Replace your for loop with:

    for (String value : content.split("@")) {
                XWPFParagraph para = doc.createParagraph();
                para.setVerticalAlignment(TextAlignment.CENTER);
                para.setNumID(addListStyle(abstractNum, doc, numbering));
                if (value.contains("Second")) {
                    para.getCTP().getPPr().getNumPr().addNewIlvl().setVal(BigInteger.valueOf(1));
                }
                XWPFRun run = para.createRun();
                run.setText(value);
            }
    

    Create a multi hierarchy bullited list in MS-Word .docx manually and inspect its XML structure by renaming its extension to .zip, inside this zip you'll find word/document.xml, by inspecting it you'll find that its <w:ilvl w:val="0"/>, "ilvl" Indent Level that is responsible for you indentation so using above code you can create you multi level lists.

    Here is how you set indent level:

    para.getCTP().getPPr().getNumPr().addNewIlvl().setVal(BigInteger.valueOf(1));
    

    Just increase indent level by BigInteger.valueOf((int)IndentLevel)

    0 讨论(0)
提交回复
热议问题