So I've been trying to make use of some heading styles in Apache POI. These are loaded from a template with the following code:
val document = XWPFDocument(template.inputStream)
val par = document.createParagraph()
par.style = "Heading 1"
Here, template is a Spring Resource.
The styles I am using are confirmed to exist in the template, they are named 'Heading 1', 'Heading 2', etc.
When I apply one of the styles to a paragraph, I am met with disappointing results. The paragraphs with these styles lack the styles whatsoever, even though the styles are still present in the document. The worst part is, that this occurs only in Microsoft Word, LibreOffice has no issues with using the template styles. Regrettably, I am required to use Microsoft Word.
I've found out, that when the template has some text using these styles present, the problem does not occur. These 'style holders' however, cannot be present in the final document, so I cannot use that.
Is there any way to make Microsoft behave properly and use these styles properly?
Result when opened in Microsoft Word
Result when the same file is opened in LibreOffice
I can define my own styles in accordance with solutions to this question: How can I use predefined formats in DOCX with POI? but I have no idea how to create a style with the numbering included, so that is why I've been trying to use the template styles.