/** * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header * the method will return this table * if there is no corresponding {@link XWPFTable} the method will return null * * @param ctTable */ public XWPFTable getTable(CTTbl ctTable) { for (XWPFTable table : tables) { if (table == null) return null; if (table.getCTTbl().equals(ctTable)) return table; } return null; }
/** * if there is a corresponding {@link XWPFTable} of the parameter * ctTable in the tableList of this header * the method will return this table, or null if there is no * corresponding {@link XWPFTable}. * * @param ctTable * @see org.apache.poi.xwpf.usermodel.IBody#getTable(CTTbl ctTable) */ public XWPFTable getTable(CTTbl ctTable) { for (XWPFTable table : tables) { if (table == null) return null; if (table.getCTTbl().equals(ctTable)) return table; } return null; }
/** * inserts an existing XWPFTable to the arrays bodyElements and tables * * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable) */ public void insertTable(int pos, XWPFTable table) { bodyElements.add(pos, table); int i = 0; for (CTTbl tbl : ctTc.getTblList()) { if (tbl == table.getCTTbl()) { break; } i++; } tables.add(i, table); }
/** * inserts an existing XWPFTable to the arrays bodyElements and tables * * @param pos * @param table */ public void insertTable(int pos, XWPFTable table) { bodyElements.add(pos, table); int i = 0; for (CTTbl tbl : headerFooter.getTblArray()) { if (tbl == table.getCTTbl()) { break; } i++; } tables.add(i, table); }
/** * get a table by its CTTbl-Object * * @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) */ public XWPFTable getTable(CTTbl ctTable) { for (int i = 0; i < tables.size(); i++) { if (getTables().get(i).getCTTbl() == ctTable) return getTables().get(i); } return null; }
/** * Inserts an existing {@link XWPFTable) into the arrays bodyElements and tables. * * @param pos Position, in the bodyElements array, to insert the table * @param table {@link XWPFTable) to be inserted * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table) */ public void insertTable(int pos, XWPFTable table) { bodyElements.add(pos, table); int i = 0; for (CTTbl tbl : ctFtnEdn.getTblList()) { if (tbl == table.getCTTbl()) { break; } i++; } tables.add(i, table); }
/** * Replace content of table in array tables at position pos with a * * @param pos * @param table */ public void setTable(int pos, XWPFTable table) { tables.set(pos, table); ctDocument.getBody().setTblArray(pos, table.getCTTbl()); }
/** * get a table by its CTTbl-Object * * @param ctTbl * @return a table by its CTTbl-Object or null * @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) */ @Override public XWPFTable getTable(CTTbl ctTbl) { for (int i = 0; i < tables.size(); i++) { if (getTables().get(i).getCTTbl() == ctTbl) { return getTables().get(i); } } return null; }
/** * inserts an existing XWPFTable to the arrays bodyElements and tables * * @param pos * @param table */ @Override public void insertTable(int pos, XWPFTable table) { bodyElements.add(pos, table); int i = 0; for (CTTbl tbl : ctDocument.getBody().getTblArray()) { if (tbl == table.getCTTbl()) { break; } i++; } tables.add(i, table); }
/** * Removes a specific table from this header / footer * * @param table - {@link XWPFTable} object to remove */ public void removeTable(XWPFTable table) { if (tables.contains(table)) { CTTbl ctTbl = table.getCTTbl(); XmlCursor c = ctTbl.newCursor(); c.removeXml(); c.dispose(); tables.remove(table); bodyElements.remove(table); } }
public XWPFTable getAllTable(CTTbl ctTbl) { for (int i = 0; i < allTables.size(); i++) { if (allTables.get(i).getCTTbl() == ctTbl) { return allTables.get(i); } } return null; }
/** * 表格设置宽度,每列平均分布 * * @param table * @param widthCM * @param cols */ public static void widthTable(XWPFTable table, float widthCM, int cols) { int width = (int)(widthCM/2.54*1440); CTTblPr tblPr = table.getCTTbl().getTblPr(); if (null == tblPr) { tblPr = table.getCTTbl().addNewTblPr(); } CTTblWidth tblW = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr.addNewTblW(); tblW.setType(0 == width ? STTblWidth.AUTO : STTblWidth.DXA); tblW.setW(BigInteger.valueOf(width)); if (0 != width) { CTTblGrid tblGrid = table.getCTTbl().getTblGrid(); if (null == tblGrid) { tblGrid = table.getCTTbl().addNewTblGrid(); } for (int j = 0; j < cols; j++) { CTTblGridCol addNewGridCol = tblGrid.addNewGridCol(); addNewGridCol.setW(BigInteger.valueOf(width / cols)); } } }
public static void styleTable(XWPFTable table, TableStyle style) { if (null == table || null == style) return; CTTblPr tblPr = table.getCTTbl().getTblPr(); if (null == tblPr) { tblPr = table.getCTTbl().addNewTblPr(); } if (null != style.getAlign()) { CTJc jc = tblPr.isSetJc() ? tblPr.getJc() : tblPr.addNewJc(); jc.setVal(style.getAlign()); } if (StringUtils.isNotBlank(style.getBackgroundColor())) { CTShd ctshd = tblPr.isSetShd() ? tblPr.getShd() : tblPr.addNewShd(); ctshd.setColor("auto"); ctshd.setVal(STShd.CLEAR); ctshd.setFill(style.getBackgroundColor()); } }
List<Row> rows=page.getRows(); XWPFTable table = document.createTable(rows.size(), totalColumn); table.getCTTbl().getTblPr().unsetTblBorders(); table.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(DxaUtils.points2dxa(tableWidth))); for(int rowNumber=0;rowNumber<rows.size();rowNumber++){ Row row=rows.get(rowNumber);
public static CTTblPr getTblPr( XWPFTable table ) { CTTbl tbl = table.getCTTbl(); if ( tbl != null ) { return tbl.getTblPr(); } return null; }
/** * get a table by its CTTbl-Object * * @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) */ public XWPFTable getTable(CTTbl ctTable) { for (int i = 0; i < tables.size(); i++) { if (getTables().get(i).getCTTbl() == ctTable) return getTables().get(i); } return null; }
/**Replace content of table in array tables at position pos with a * @param pos * @param table */ public void setTable(int pos, XWPFTable table) { tables.set(pos, table); ctDocument.getBody().setTblArray(pos, table.getCTTbl()); }
private void copyTableRow(final XWPFTable posTbl, final int rowCounter) { XWPFTableRow rowToCopy = posTbl.getRow(1); CTRow row = posTbl.getCTTbl().insertNewTr(rowCounter); row.set(rowToCopy.getCtRow()); XWPFTableRow copyRow = new XWPFTableRow(row, posTbl); posTbl.getRows().add(rowCounter, copyRow); }