In an docx document i want to be able to get a list with all Headings (chapters) in the file. Every text that has 'Heading 1', 'Heading 2' etc. This is the word file:
I am using apache POI to read into the file. However when i try to get the style from a paragraph or a run it always returns NULL.
File f=new File("src/TestFile.docx");
FileInputStream fis = new FileInputStream(f);
XWPFDocument xdoc=new XWPFDocument(OPCPackage.open(fis));
XWPFStyles styles = xdoc.getStyles();
java.util.List<XWPFParagraph> xwpfparagraphs = new ArrayList<XWPFParagraph>();
xwpfparagraphs = xdoc.getParagraphs();
System.out.println("Styleid paragraph: " +xwpfparagraphs.get(0).getStyleID());
XWPFParagraph paragraph = xwpfparagraphs.get(0);
for (XWPFRun run : paragraph.getRuns()) {
System.out.println("Styleid run: " + run.getStyle());
}
Output:
Styleid paragraph: null
Styleid run:
Styleid run:
Styleid run:
So the problem is, how can i recognize the headings if i can't trace back the style of the text? How to do this correctly?
