List of usage examples for org.apache.poi.xwpf.usermodel XWPFTable XWPFTable
public XWPFTable(CTTbl table, IBody part, int row, int col)
From source file:com.deepoove.poi.NiceXWPFDocument.java
License:Apache License
/** * ???/*from w w w . j a v a 2s . com*/ * * @param run * @param row * @param col * @return */ public XWPFTable insertNewTable(XWPFRun run, int row, int col) { XmlCursor cursor = ((XWPFParagraph) run.getParent()).getCTP().newCursor(); // XmlCursor cursor = run.getCTR().newCursor(); if (isCursorInBody(cursor)) { String uri = CTTbl.type.getName().getNamespaceURI(); String localPart = "tbl"; cursor.beginElement(localPart, uri); cursor.toParent(); CTTbl t = (CTTbl) cursor.getObject(); XWPFTable newT = new XWPFTable(t, this, row, col); XmlObject o = null; while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) { o = cursor.getObject(); } if (!(o instanceof CTTbl)) { tables.add(0, newT); } else { int pos = tables.indexOf(getTable((CTTbl) o)) + 1; tables.add(pos, newT); } int i = 0; XmlCursor tableCursor = t.newCursor(); try { cursor.toCursor(tableCursor); while (cursor.toPrevSibling()) { o = cursor.getObject(); if (o instanceof CTP || o instanceof CTTbl) i++; } bodyElements.add(i, newT); cursor.toCursor(tableCursor); cursor.toEndToken(); return newT; } finally { tableCursor.dispose(); } } return null; }
From source file:org.obeonetwork.m2doc.generator.TemplateProcessor.java
License:Open Source License
@Override public AbstractConstruct caseTable(Table object) { // Create the table structure in the destination document. XWPFTable generatedTable;// www. java2s. c om CTTbl copy = (CTTbl) object.getTable().getCTTbl().copy(); copy.getTrList().clear(); if (generatedDocument instanceof XWPFDocument) { generatedTable = ((XWPFDocument) generatedDocument).createTable(); if (generatedTable.getRows().size() > 0) { generatedTable.removeRow(0); } generatedTable.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); generatedTable = tCell.getTables().get(tableRank); } else { throw new UnsupportedOperationException("unknown type of IBody : " + generatedDocument.getClass()); } // iterate on the row for (Row row : object.getRows()) { XWPFTableRow newRow = generatedTable.createRow(); CTRow ctRow = (CTRow) row.getTableRow().getCtRow().copy(); ctRow.getTcList().clear(); newRow.getCtRow().set(ctRow); // iterate on cells. for (Cell cell : row.getCells()) { XWPFTableCell newCell = newRow.createCell(); CTTc ctCell = (CTTc) cell.getTableCell().getCTTc().copy(); ctCell.getPList().clear(); ctCell.getTblList().clear(); newCell.getCTTc().set(ctCell); // process the cell : TemplateProcessor processor = new TemplateProcessor(definitions, queryEnvironment, newCell); processor.doSwitch(cell.getTemplate()); } } return super.caseTable(object); }
From source file:org.obeonetwork.m2doc.generator.UserContentRawCopy.java
License:Open Source License
/** * Create new Table./*from w ww . java 2 s .c o m*/ * TODO OHA fix bug in nested table on usercontent (else case in code) * * @param document * document * @param inputTable * input Table * @return get Table */ private XWPFTable createNewTable(IBody document, XWPFTable inputTable) { XWPFTable generatedTable; CTTbl copy = (CTTbl) inputTable.getCTTbl().copy(); if (document instanceof XWPFDocument) { generatedTable = ((XWPFDocument) document).createTable(); } else if (document instanceof XWPFTableCell) { XWPFTableCell tCell = (XWPFTableCell) document; int tableRank = tCell.getTables().size(); generatedTable = new XWPFTable(copy, tCell, 0, 0); tCell.insertTable(tableRank, generatedTable); generatedTable = tCell.getTables().get(tableRank); } else { throw new UnsupportedOperationException("unknown type of IBody : " + document.getClass()); } return generatedTable; }