java - Apache POI Word using custom styles for titles -
i trying create heading titles in word (.docx) document, using apache-poi.
i have template contains custom styles , example of heading titles using custom styles.
xwpfdocument document=new xwpfdocument(new fileinputstream("template.docx")); my custom style called "custom_ynp" (i created directly in word), when use line below, returns false
document.getstyles().styleexist("custom_ynp") and, of course, when try use style, doesn't work, print string in "normal" style
xwpfparagraph paragraph=document.createparagraph(); paragraph.setstyle("custom_ynp"); xwpfrun run=paragraph.createrun(); run.settext("test"); just record, "save document" line :
document.write(new fileoutputstream("mydoc.docx")); i have read question, can't find solution problem... how can use predefined formats in docx poi?
edit : works if create own style using apache-poi.... still woudl use existing styles word document.
a *.docx zip archive. can unzip , /word/styles.xml. there see w:styleid="customynp" without underscore. name "custom_ynp" <w:name w:val="custom_ynp"/>. so:
xwpfdocument document = new xwpfdocument(new fileinputstream("template.docx")); system.out.println(document.getstyles().styleexist("customynp")); system.out.println(document.getstyles().getstyle("customynp").getname()); xwpfparagraph paragraph=document.createparagraph(); paragraph.setstyle("customynp"); xwpfrun run=paragraph.createrun(); run.settext("test"); document.write(new fileoutputstream("mydoc.docx")); document.close();
Comments
Post a Comment