Я прочитал документ Word в Java, используя Apache POI, но я не могу найти ссылки на создание раздела, подраздел ect. в файле Word. Кроме того, я пытаюсь создать оглавление с количеством добавленных разделов. Я скопировал часть моего кода, чтобы показать вам, что я сделал:Как создать раздел, подраздел и подзапрос в файле Word с помощью Apache POI?
public static void main(String[] args) throws FileNotFoundException, IOException {
File out = new File("POIExamlpe.docx");
XWPFDocument document = new XWPFDocument();
XWPFStyles styles = document.createStyles();
XWPFWordExtractor we = new XWPFWordExtractor(document);
System.out.println(we.getText());
//Create multilevel list in word with different styles, form the next level
CreateParagraph(document, styles, "First [email protected]@Second [email protected]@First [email protected]@Second [email protected]@Three [email protected]@Second [email protected]@Three [email protected]@Second [email protected]@First Level");
document.createTOC();
}
public static void CreateParagraph(XWPFDocument doc, XWPFStyles style,String content){
for (String value : content.split("@@")) {
XWPFParagraph para = doc.createParagraph();
para.setVerticalAlignment(TextAlignment.CENTER);
para.setNumID(BigInteger.valueOf(1));
para.setStyle(heading1);
if (value.contains("Second")) { para.getCTP().getPPr().getNumPr().addNewIlvl().setVal(BigInteger.valueOf(1));
para.setStyle(heading2);
}
if(value.contains("Three")){ para.getCTP().getPPr().getNumPr().addNewIlvl().setVal(BigInteger.valueOf(2));
para.setStyle(heading4);
}
XWPFRun run = para.createRun();
}
Я сгенерирована document
Но я хочу, чтобы создать что-то вроде this.
Спасибо Axel за ваше время. Ваш ответ решил мою проблему. Это сработало отлично! – Sofi