xwpf

How do I change color of a particular word document using apache poi?

耗尽温柔 提交于 2019-11-28 08:19:50
问题 Current output: Needed output: above are the snapshots of the .docx and below is the code sample code, I want to change the color of a after it is replaced by @ . r.setColor("DC143C") doesn't work: for (XWPFParagraph p : docx.getParagraphs()) { List<XWPFRun> runs = p.getRuns(); if (runs != null) { for (XWPFRun r : runs) { String origText = r.getText(0); if (origText != null && origText.contains("a")) { origText = origText.replace("a", "@"); r.setText(origText, 0); } } } } 回答1: If the need is

How to set page orientation for Word document?

断了今生、忘了曾经 提交于 2019-11-28 00:57:36
问题 I use Apache POI XWPF to create and handle MS Word documents. But I didn't find in the documentation how to change the page orientation. Apparently this way should make it: XWPFDocument doc = new XWPFDocument(); CTDocument1 document = doc.getDocument(); CTBody body = document.getBody(); if (!body.isSetSectPr()) { body.addNewSectPr(); } CTSectPr section = body.getSectPr(); if(!section.isSetPgSz()) { section.addNewPgSz(); } CTPageSz pageSize = section.getPgSz(); pageSize.setOrient

How can I use predefined formats in DOCX with POI?

≯℡__Kan透↙ 提交于 2019-11-27 13:05:56
问题 I'm creating a docx generator with POI and would like to use predefined formats. Word includes several formats like Title, Heading 1..10 etc. These formats are predefined in every DOCX you create with Word. I would like to use them in my docx generator. I tried the following but the format was not applied: paragraph = document.createParagraph(); lastParagraph.setStyle("Heading1"); I also tried "heading 1", "heading1" and "Heading1" as style, but none of them worked. The API documentation

How to replace placeholders in header of docx in java using poi 3.8

本秂侑毒 提交于 2019-11-27 07:12:21
问题 I'm tying to replace tokens in the header of docx file.I have handled the token replacement in paragraphs and tables but its not picking the header data. Im using apache poi 3.8 and coding in java using eclipse ID. Thanx 回答1: This methods will replace all selected text, in tables, headers and paragraph, in the entire document. public XWPFDocument replacePOI(XWPFDocument doc, String placeHolder, String replaceText){ // REPLACE ALL HEADERS for (XWPFHeader header : doc.getHeaderList())