Bug 57618 - How to set heading style for a paragraph in a docx file using Apache POI ?
Summary: How to set heading style for a paragraph in a docx file using Apache POI ?
Status: CLOSED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-23 07:41 UTC by furkan
Modified: 2015-02-23 14:32 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description furkan 2015-02-23 07:41:13 UTC
I am trying to create a docx file with poi but I cannot set heading style for a paragraph. My code structure is like below;

    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");    // not working

    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. 

regards
Comment 1 furkan 2015-02-23 09:25:06 UTC
I found a solution in the link below

http://stackoverflow.com/questions/2643822/how-can-i-use-predefined-formats-in-docx-with-poi


But If you have another solution without using template file, please let me know :))

regards
Comment 2 Nick Burch 2015-02-23 14:00:28 UTC
If you'd like to write this us as an Example, which we can then ship with POI to help others in future, we'd love to have your contribution!
Comment 3 furkan 2015-02-23 14:32:07 UTC
OK. What should I do to do so ?