2

I am creating the content of a docx file and try to have headings above tables I create. I currently create the text like that:

XWPFParagraph newParagraph = document.insertNewParagraph(cursor);
XWPFRun run = newParagraph.createRun();
run.setText(headingCounter + ": Heading");

My problem is that this is a normal text and not a heading which also leads to the text not being shown in the table of content. How can I solve this?

shtanddwn
  • 33
  • 4
  • 1
    Set the style for the paragraph to be a heading style? – Gagravarr Sep 27 '22 at 14:46
  • @Gagravarr So Headings are normal paragraphs with runs and text with different style and changing the style would also include them in the table of content? – shtanddwn Sep 27 '22 at 14:48
  • Word `.docx` files are a zip of XML files. Just setup a document how you want in Word, rename to `.zip`, unpack and look at what Word decided to stuff into the XML. Once you know how it is done by Word you know what to ask POI to recreate for your specific case – Gagravarr Sep 27 '22 at 14:57

0 Answers0