xwpf

How to merge cells horizontally using apache-poi

余生颓废 提交于 2019-12-11 12:24:12
问题 I get to do a vertically merged using this function: private static void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) { for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) { XWPFTableCell cell = table.getRow(rowIndex).getCell(col); if ( rowIndex == fromRow ) { // The first merged cell is set with RESTART merge value cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART); } else { // Cells which join (merge) the first one, are set with CONTINUE

Apache POI - Split Word document (docx) to pages

早过忘川 提交于 2019-12-10 10:43:40
问题 I have been trying to segment a docx document to multiple documents based on a predefined criteria. following is my approach to cut it to paragraphs try { FileInputStream in = new FileInputStream(file); XWPFDocument doc = new XWPFDocument(in); List<XWPFParagraph> paragraphs = doc.getParagraphs(); for (int idx = 0; idx < paragraphs.size(); idx++) { XWPFDocument outputDocument = new XWPFDocument(); createParagraphInAnotherDocument(outputDocument, paragraphs.get(idx).getText()); String fullPath

How to merge cells (or apply colspan) using XWPFTable in POI in Java?

∥☆過路亽.° 提交于 2019-12-07 03:59:07
问题 Creating a table in poi was quite easy but it has very limited tutorials and I cannot find one that can create a simple merged cell in a table in generating a docx file. 回答1: If you have created table, row inside a table and cell inside a row, you can add gridSpan to cell properties: if (cell.getCTTc().getTcPr() == null) cell.getCTTc().addNewTcPr(); if (cell.getCTTc().getTcPr().getGridSpan() == null) cell.getCTTc().getTcPr().addNewGridSpan(); cell.getCTTc().getTcPr().getGridSpan().setVal(2);

Apache POI - Split Word document (docx) to pages

痴心易碎 提交于 2019-12-06 07:34:20
I have been trying to segment a docx document to multiple documents based on a predefined criteria. following is my approach to cut it to paragraphs try { FileInputStream in = new FileInputStream(file); XWPFDocument doc = new XWPFDocument(in); List<XWPFParagraph> paragraphs = doc.getParagraphs(); for (int idx = 0; idx < paragraphs.size(); idx++) { XWPFDocument outputDocument = new XWPFDocument(); createParagraphInAnotherDocument(outputDocument, paragraphs.get(idx).getText()); String fullPath = String.format("./content/output/%1$s_%2$s_%3$04d.docx", FileUtils.getFileName(file), getName(), idx);

How to merge cells (or apply colspan) using XWPFTable in POI in Java?

帅比萌擦擦* 提交于 2019-12-05 06:04:25
Creating a table in poi was quite easy but it has very limited tutorials and I cannot find one that can create a simple merged cell in a table in generating a docx file. If you have created table, row inside a table and cell inside a row, you can add gridSpan to cell properties: if (cell.getCTTc().getTcPr() == null) cell.getCTTc().addNewTcPr(); if (cell.getCTTc().getTcPr().getGridSpan() == null) cell.getCTTc().getTcPr().addNewGridSpan(); cell.getCTTc().getTcPr().getGridSpan().setVal(2); Note: cell is org.apache.poi.xwpf.usermodel.XWPFTableCell. Creating a separate XWPFTable for each table row

Remove images in .docx file

喜你入骨 提交于 2019-12-04 14:15:17
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().removeDrawing(0); } } } } Exception: Exception in thread "main" java.lang.IndexOutOfBoundsException at org

Landscape and portrait pages in the same word document using Apache POI XWPF in Java

北城以北 提交于 2019-12-02 17:12:41
问题 I am trying to use Java and the Apache POI library to create a word document that contained some landscape and some portrait pages. I can change the orientation of all the pages, but is there a way to change just the orientation of some of them? I have tried using different sections and bodies, but to no avail. At the moment I have written a function that takes a XWPFDocument as input and changes the orientation of a new body. I had hoped changing the orientation for new body would not affect

Landscape and portrait pages in the same word document using Apache POI XWPF in Java

你说的曾经没有我的故事 提交于 2019-12-02 09:27:18
I am trying to use Java and the Apache POI library to create a word document that contained some landscape and some portrait pages. I can change the orientation of all the pages, but is there a way to change just the orientation of some of them? I have tried using different sections and bodies, but to no avail. At the moment I have written a function that takes a XWPFDocument as input and changes the orientation of a new body. I had hoped changing the orientation for new body would not affect the previous pages, but it affects the entire document. private void changeOrientation(XWPFDocument

How to add a table to header or footer?

瘦欲@ 提交于 2019-12-02 02:56:23
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(XWPFHeaderFooterPolicy.DEFAULT); // somthing like: header.createTable(); Any help will be more than

Removing an XWPFParagraph keeps the paragraph symbol (¶) for it

♀尐吖头ヾ 提交于 2019-12-02 00:04:07
I am trying to remove a set of contiguous paragraphs from a Microsoft Word document, using Apache POI . From what I have understood, deleting a paragraph is possible by removing all of its runs, this way: /* * Deletes the given paragraph. */ public static void deleteParagraph(XWPFParagraph p) { if (p != null) { List<XWPFRun> runs = p.getRuns(); //Delete all the runs for (int i = runs.size() - 1; i >= 0; i--) { p.removeRun(i); } p.setPageBreak(false); //Remove the eventual page break } } In fact, it works, but there's something strange. The block of removed paragraphs does not disappear from