List of usage examples for org.apache.poi.xwpf.usermodel XWPFTable XWPFTable
public XWPFTable(CTTbl table, IBody part)
From source file:com.foc.vaadin.gui.mswordGenerator.MSWordWrapper.java
License:Apache License
@Override public XWPFTable insertTable() { XWPFTable newTable = null;//from www . j ava 2 s . co m if (tableCell != null) { // wordDocument.getDocument().getDomNode() // XWPFTable newTable = new XWPFTable(); // XmlCursor xmlCursor = wordDocument.getDocument().getBody().newCursor(); // xmlCursor.to // tableCell.insertNewTbl(arg0) // XWPFParagraph dummyParaphraph = insertParagraph(); // XWPFRun run = dummyParaphraph.createRun(); // run.setText("Dummy"); tableCell.setText("Wao"); List<XWPFParagraph> listParagraphs = tableCell.getParagraphs(); if (listParagraphs.size() > 0) { XWPFParagraph paragraph = listParagraphs.get(0); tableCell.removeParagraph(0); } CTTbl cttbl = tableCell.getCTTc().addNewTbl(); tableCell.getCTTc().addNewP(); newTable = new XWPFTable(cttbl/*wordDocument.getDocument().getBody().getTblArray(0)*/, tableCell); tableCell.insertTable(0, newTable); } else if (wordDocument != null) { newTable = wordDocument.createTable(); } return newTable; }
From source file:fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.java
License:Open Source License
/** * Add body elements from the given token source. * // w w w . j a v a 2s. c o m * @param source * @param part * @param bodyElements */ private void addBodyElements(XmlTokenSource source, IBody part, List<IBodyElement> bodyElements) { // parse the document with cursor and add // the XmlObject to its lists XmlCursor cursor = source.newCursor(); cursor.selectPath("./*"); while (cursor.toNextSelection()) { XmlObject o = cursor.getObject(); if (o instanceof CTSdtBlock) { // <w:sdt><w:sdtContent><p... CTSdtBlock block = (CTSdtBlock) o; CTSdtContentBlock contentBlock = block.getSdtContent(); if (contentBlock != null) { addBodyElements(contentBlock, part, bodyElements); } } else if (o instanceof CTP) { XWPFParagraph p = new XWPFParagraph((CTP) o, part); bodyElements.add(p); } else if (o instanceof CTTbl) { XWPFTable t = new XWPFTable((CTTbl) o, part); bodyElements.add(t); } } cursor.dispose(); }
From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java
License:Open Source License
/** * Inserts the given {@link MTable}./*from w w w . j a va2 s . co m*/ * * @param run * the {@link XWPFRun} to insert to * @param table * the {@link MTable} to insert */ private void insertMTable(XWPFRun run, MTable table) { final XWPFTable docTable; if (generatedDocument instanceof XWPFDocument) { if (table.getLabel() != null) { XWPFRun captionRun; captionRun = run; IRunBody runBody = captionRun.getParent(); if (runBody instanceof XWPFParagraph) { ((XWPFParagraph) runBody).setSpacingAfter(0); } captionRun.setText(table.getLabel()); captionRun.setBold(true); } docTable = ((XWPFDocument) generatedDocument).createTable(); } else if (generatedDocument instanceof XWPFHeaderFooter) { final XWPFHeaderFooter headerFooter = (XWPFHeaderFooter) generatedDocument; final int index = headerFooter._getHdrFtr().getTblArray().length; final CTTbl cttbl = headerFooter._getHdrFtr().insertNewTbl(index); docTable = new XWPFTable(cttbl, headerFooter); headerFooter.insertTable(index, docTable); } else if (generatedDocument instanceof XWPFTableCell) { XWPFTableCell tcell = (XWPFTableCell) generatedDocument; if (table.getLabel() != null) { final XWPFRun captionRun = run; IRunBody runBody = captionRun.getParent(); if (runBody instanceof XWPFParagraph) { ((XWPFParagraph) runBody).setSpacingAfter(0); } captionRun.setText(table.getLabel()); captionRun.setBold(true); } CTTbl ctTbl = tcell.getCTTc().addNewTbl(); docTable = new XWPFTable(ctTbl, tcell); int tableRank = tcell.getTables().size(); tcell.insertTable(tableRank, docTable); // A paragraph is mandatory at the end of a cell, so let's always add one. tcell.addParagraph(); } else { docTable = null; M2DocUtils.appendMessageRun((XWPFParagraph) run.getParent(), ValidationMessageLevel.ERROR, "m:table can't be inserted here."); } if (docTable != null) { fillTable(docTable, table); } }
From source file:org.obeonetwork.m2doc.generator.M2DocEvaluator.java
License:Open Source License
@Override public IConstruct caseTable(Table table) { // Create the table structure in the destination document. CTTbl copy = (CTTbl) table.getTable().getCTTbl().copy(); copy.getTrList().clear();//from www.j av a 2s. c o m if (generatedDocument instanceof XWPFDocument) { currentGeneratedTable = ((XWPFDocument) generatedDocument).createTable(); if (currentGeneratedTable.getRows().size() > 0) { currentGeneratedTable.removeRow(0); } currentGeneratedTable.getCTTbl().set(copy); } else if (generatedDocument instanceof XWPFHeaderFooter) { final XWPFHeaderFooter headerFooter = (XWPFHeaderFooter) generatedDocument; final int index = headerFooter._getHdrFtr().getTblArray().length; final CTTbl cttbl = headerFooter._getHdrFtr().insertNewTbl(index); XWPFTable newTable = new XWPFTable(cttbl, headerFooter); if (newTable.getRows().size() > 0) { newTable.removeRow(0); } headerFooter.insertTable(index, newTable); currentGeneratedTable = headerFooter.getTables().get(index); currentGeneratedTable.getCTTbl().set(copy); } else if (generatedDocument instanceof XWPFTableCell) { XWPFTableCell tCell = (XWPFTableCell) generatedDocument; int tableRank = tCell.getTables().size(); XWPFTable newTable = new XWPFTable(copy, tCell, 0, 0); if (newTable.getRows().size() > 0) { newTable.removeRow(0); } tCell.insertTable(tableRank, newTable); currentGeneratedTable = tCell.getTables().get(tableRank); } else { throw new UnsupportedOperationException("unknown type of IBody : " + generatedDocument.getClass()); } // iterate on the row for (Row row : table.getRows()) { doSwitch(row); } return table; }
From source file:org.obeonetwork.m2doc.generator.TableClientProcessor.java
License:Open Source License
/** * Create a table in a table cell.// ww w .ja v a 2 s .com * * @param tableRun * The table run * @param first * whether it's the 1st table created in this cell * @param mtable * The table description * @param tcell * The cell in which to create a new table * @return The newly creatted table, located in the given cell. */ private XWPFTable createTableInCell(XWPFRun tableRun, boolean first, MTable mtable, XWPFTableCell tcell) { XWPFTable table; if (showTitle() && mtable.getLabel() != null) { XWPFRun captionRun; if (first) { captionRun = tableRun; IRunBody runBody = captionRun.getParent(); if (runBody instanceof XWPFParagraph) { ((XWPFParagraph) runBody).setSpacingAfter(0); } } else { XWPFParagraph captionParagraph = tcell.addParagraph(); captionParagraph.setSpacingAfter(0); captionRun = captionParagraph.createRun(); } captionRun.setText(mtable.getLabel()); captionRun.setBold(true); } CTTbl ctTbl = tcell.getCTTc().addNewTbl(); table = new XWPFTable(ctTbl, tcell); int tableRank = tcell.getTables().size(); tcell.insertTable(tableRank, table); // A paragraph is mandatory at the end of a cell, so let's always add one. tcell.addParagraph(); return table; }