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

孤街浪徒 提交于 2019-12-01 18:00:31

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)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!