This question already has an answer here:
I am trying to create a docx file with poi but I cannot set heading style for a paragraph.
XWPFDocument document= new XWPFDocument();
//Write the Document in file system
FileOutputStream out = new FileOutputStream(new File("C:/Users/2/Desktop/RequirementModelDocument.docx"));
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run=paragraph.createRun();
paragraph.setAlignment(ParagraphAlignment.LEFT);
paragraph.setStyle("Heading1");
run.setText(reqLevel.getName());
run.setBold(true);
run.setFontFamily("Calibri Light (Headings)");
Its like ignores the paragraph.setStyle("Heading1");
line. I've looked at the apache's examples but I could not see any example about this issue.
I found a solution in the link below. Sorry for duplication.
How can I use predefined formats in DOCX with POI?
But, If you have any other solution without using template file, please let me know :)
regards
If you start a new document, there are no style defined. Either start from an existing template and copy the styles, or create your own (like I did, based on https://stackoverflow.com/a/27864752/461499 )
See here:
And