I've been looking for a way to create a Table of content for my Word document. I have placed this code block to add the table of contents:
- Code: Select all
Section section = doc.addSection();
TableOfContent table = new TableOfContent(doc, "{\\o \"1-9\" \\h \\z \\u}");
Paragraph paragraph = section.addParagraph();
paragraph.appendTOC(1, 2);
paragraph.getItems().add(table);
doc.updateTableOfContents();
It gives me an error:
java.lang.NullPointerException: Cannot invoke "com.spire.doc.packages.sprhds.spr??()" because the return value of "com.spire.doc.packages.sprwks.spr??()" is null
I have previously created several sections in my document.