xwpf

How to add a table to header or footer?

半城伤御伤魂 提交于 2020-01-11 11:28:29
问题 I'm having serious trouble adding a new, simple XWPFTable to an XWPFHeader (or Footer). Unfortunately there seems to be only one guy having the same problem (https://bz.apache.org/bugzilla/show_bug.cgi?id=57366#c0). Does anyone has an approach to achieve this?? XWPFDocument docx = (XWPFDocument) dockingObject; CTSectPr sectPr = docx.getDocument().getBody().addNewSectPr(); XWPFHeaderFooterPolicy policy = new WPFHeaderFooterPolicy(docx, sectPr); XWPFHeader header = policy.createHeader

How can I add embedded equations to docx files by using Apache POI?

天大地大妈咪最大 提交于 2020-01-11 07:47:55
问题 I want to create a docx file programatically via Apache POI. I want to add some mathematical equations in some lines. How can I do this in a way that when the user open the docx file it see that equations as docx equation form. I mean I don't want simply give a background colour to that run, I want when the user does double click on my equation MS-Word open it in equation forms. Thanks in advance 回答1: This is not really complicated: import java.io.FileOutputStream; import org.apache.poi.xwpf

How can I set background colour of a run (a word in line or a paragraph) in a docx file by using Apache POI?

巧了我就是萌 提交于 2019-12-29 01:01:33
问题 I want to create a docx file by using Apache POI. I want to set background colour of a run (i.e. a word or some parts of a paragraph). How can I do this? Is in possible via Apache POI or not. Thanks in advance 回答1: Word provides two possibilities for this. There are really background colors possible within runs. But there are also so called highlighting settings. With XWPF both possibilities are only possible using the underlying objects CTShd and CTHighlight . But while CTShd is shipped with

Apache POI: How do you restart numbering on a numbered list in word document?

只愿长相守 提交于 2019-12-25 08:14:36
问题 I'm trying to use Apache POI XWPF library to produce a report in a Word docx file. My approach is to use an existing Word Document as a Styles template. Within the template I defined a style named "SRINumberList". So to load the template and remove everything that's not in the Header or Footer: protected void createDocFromTemplate() { try { document = new XWPFDocument(this.getClass().getResourceAsStream(styleTemplate)); int pos = document.getBodyElements().size()-1; while (pos >= 0) {

How to create a header/footer in new docx document?

故事扮演 提交于 2019-12-24 02:18:59
问题 I would like to create a header and footer on a docx document (a new one and not existing one) with XWPF jars (apache poi). When I use XWPFHeaderFooterPolicy policy = document.getHeaderFooterPolicy(); policy is null, so I would know how to create it in a new document. CustomXWPFDocument document = new CustomXWPFDocument(); XWPFHeaderFooterPolicy policy = document.getHeaderFooterPolicy(); XWPFHeader head = policy.createHeader(policy.DEFAULT); head.getListParagraph().get(0).createRun().setText(

how to set page margins for word document using apache poi?

孤者浪人 提交于 2019-12-23 07:31:40
问题 I want to set page-margins for word document created using apache poi-3.9. I found it can be done using CTPageMar but CTPageMar is not being resolved. I am using apache poi-3.9 I tried this CTSectPr sectPr = document.getDocument().getBody().addNewSectPr(); CTPageMar pageMar = sectPr.addNewPgMar(); pageMar.setLeft(BigInteger.valueOf(720L)); pageMar.setTop(BigInteger.valueOf(1440L)); pageMar.setRight(BigInteger.valueOf(720L)); pageMar.setBottom(BigInteger.valueOf(1440L)); 回答1: As far as I

Remove images in .docx file

一曲冷凌霜 提交于 2019-12-21 20:17:06
问题 Do we have the option to remove pictures from .docx file in java using xwpfdocument ? Please reply me since I'm trying to do it for past one week. Code tried: public static void imageProcess(XWPFDocument document) throws IOException { List<XWPFPictureData> pic=document.getAllPictures(); Iterator<XWPFPictureData> iterator=pic.iterator(); if (pic.size()>0) { for (XWPFParagraph para : document.getParagraphs()) { List<XWPFRun> runs = para.getRuns(); for( XWPFRun run : runs ){ run.getCTR()

XWPF new paragraph in a table cell

杀马特。学长 韩版系。学妹 提交于 2019-12-14 03:03:26
问题 I am trying to create a simple table with one column. I create a new row and in each row a new paragraph. The problem is that each row starts with one empty line - I guess the new paragraph creates it. I was trying to set spacing before, indentation etc. with no success. for (int i=0; i<questions.size(); i++) { Question question = questions.get(i); XWPFTableRow row = table.getRow(i); XWPFTableCell cell = row.getCell(0); XWPFParagraph paragraph = cell.addParagraph(); XWPFRun run = paragraph

Check if XWPFRun is highlighted

邮差的信 提交于 2019-12-12 02:44:23
问题 For Apache POI, I am reading Word documents, both doc and docx. The old CharacterRun for doc has an isHighlighted function that tells me if text is highlighted or not. Is there an equivalent function for XWPFRun for docx files? 回答1: After a lot of research and analysis, I was able to figure out there is a function in the CTRPr class. //p is the XWPFParagraph for (XWPFRun pRun : p.getRuns()) { CTRPr ctrpr = pRun.getCTR().getRPr(); if (ctrpr != null && ctrpr.isSetHighlight()) { //This is

Does the XWPF of Apache POI support paragraph's authohyphenation feature?

允我心安 提交于 2019-12-11 15:16:56
问题 I know, that HWPF has this feature, but I can't find any simular in XWPF. Maybe there are workarounds for solving this problem. If you know some, please share with me. Thanks in advance! 回答1: In Word Office OpenXML the automatic hyphenation settings are set for the whole document and may be suppressed for single paragraphs. The settings for the whole document are in /word/settings.xml part of the package. This is XWPFSettings but it is not possible to get this using the high level objects of