/** * get the StyleID of the table * * @return style-ID of the table */ public String getStyleID() { String styleId = null; CTTblPr tblPr = ctTbl.getTblPr(); if (tblPr != null) { CTString styleStr = tblPr.getTblStyle(); if (styleStr != null) { styleId = styleStr.getVal(); } } return styleId; }
/** * Returns CTTblPr object for table. If force parameter is true, will * create the element if necessary. If force parameter is false, returns * null when CTTblPr element is missing. * * @param force - force creation of CTTblPr element if necessary */ private CTTblPr getTblPr(boolean force) { return (ctTbl.getTblPr() != null) ? ctTbl.getTblPr() : (force ? ctTbl.addNewTblPr() : null); }
/** * 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); } }
/** * add a new Row to the table * at position pos * * @param row the row which should be added */ public boolean addRow(XWPFTableRow row, int pos) { if (pos >= 0 && pos <= tableRows.size()) { ctTbl.insertNewTr(pos); ctTbl.setTrArray(pos, row.getCtRow()); tableRows.add(pos, row); return true; } return false; }
/** * add a new Row to the table * * @param row the row which should be added */ public void addRow(XWPFTableRow row) { ctTbl.addNewTr(); ctTbl.setTrArray(getNumberOfRows() - 1, row.getCtRow()); tableRows.add(row); }
/** * 表格设置宽度,每列平均分布 * * @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)); } } }
/** * create a new XWPFTableRow object with as many cells as the number of columns defined in that moment * * @return tableRow */ public XWPFTableRow createRow() { int sizeCol = ctTbl.sizeOfTrArray() > 0 ? ctTbl.getTrArray(0) .sizeOfTcArray() : 0; XWPFTableRow tabRow = new XWPFTableRow(ctTbl.addNewTr(), this); addColumn(tabRow, sizeCol); tableRows.add(tabRow); return tabRow; }
private void createEmptyTable(CTTbl table) { // MINIMUM ELEMENTS FOR A TABLE table.addNewTr().addNewTc().addNewP(); CTTblPr tblpro = table.addNewTblPr(); tblpro.addNewTblW().setW(new BigInteger("0")); tblpro.getTblW().setType(STTblWidth.AUTO); // layout // tblpro.addNewTblLayout().setType(STTblLayoutType.AUTOFIT); // borders CTTblBorders borders = tblpro.addNewTblBorders(); borders.addNewBottom().setVal(STBorder.SINGLE); borders.addNewInsideH().setVal(STBorder.SINGLE); borders.addNewInsideV().setVal(STBorder.SINGLE); borders.addNewLeft().setVal(STBorder.SINGLE); borders.addNewRight().setVal(STBorder.SINGLE); borders.addNewTop().setVal(STBorder.SINGLE); /* * CTTblGrid tblgrid=table.addNewTblGrid(); * tblgrid.addNewGridCol().setW(new BigInteger("2000")); */ //getRows(); }
/** * add a new column for each row in this table */ public void addNewCol() { if (ctTbl.sizeOfTrArray() == 0) { createRow(); } for (int i = 0; i < ctTbl.sizeOfTrArray(); i++) { XWPFTableRow tabRow = new XWPFTableRow(ctTbl.getTrArray(i), this); tabRow.createCell(); } }
public static float[] computeColWidths( CTTbl table ) { CTTblGrid grid = table.getTblGrid(); List<CTTblGridCol> cols = getGridColList( grid ); int nbColumns = cols.size(); float[] colWidths = new float[nbColumns]; float colWidth = -1; int nbColumnsToIgnoreBefore = 0; for ( int i = nbColumnsToIgnoreBefore; i < colWidths.length; i++ ) { CTTblGridCol tblGridCol = cols.get( i ); colWidth = tblGridCol.getW().floatValue(); colWidths[i] = dxa2points( colWidth ); } return colWidths; }
CTTblPr ctTblPr = ctTbl.addNewTblPr(); CTTblLayoutType layoutType = ctTblPr.addNewTblLayout(); layoutType.setType(STTblLayoutType.FIXED); CTTblGrid grid = ctTbl.addNewTblGrid(); for (int i = 0; i < 3; i++) { CTTblGridCol gridCol = grid.addNewGridCol();
/** * inserts a new tablerow * * @param pos * @return the inserted row */ public XWPFTableRow insertNewTableRow(int pos) { if (pos >= 0 && pos <= tableRows.size()) { CTRow row = ctTbl.insertNewTr(pos); XWPFTableRow tableRow = new XWPFTableRow(row, this); tableRows.add(pos, tableRow); return tableRow; } return null; }
CTTblGrid tblGrid = table.getCTTbl().getTblGrid(); if (null == tblGrid) { tblGrid = table.getCTTbl().addNewTblGrid();
/** * create a new XWPFTableRow object with as many cells as the number of columns defined in that moment * * @return tableRow */ public XWPFTableRow createRow() { int sizeCol = ctTbl.sizeOfTrArray() > 0 ? ctTbl.getTrArray(0) .sizeOfTcArray() : 0; XWPFTableRow tabRow = new XWPFTableRow(ctTbl.addNewTr(), this); addColumn(tabRow, sizeCol); tableRows.add(tabRow); return tabRow; }
private void createEmptyTable(CTTbl table) { // MINIMUM ELEMENTS FOR A TABLE table.addNewTr().addNewTc().addNewP(); CTTblPr tblpro = table.addNewTblPr(); tblpro.addNewTblW().setW(new BigInteger("0")); tblpro.getTblW().setType(STTblWidth.AUTO); // layout // tblpro.addNewTblLayout().setType(STTblLayoutType.AUTOFIT); // borders CTTblBorders borders = tblpro.addNewTblBorders(); borders.addNewBottom().setVal(STBorder.SINGLE); borders.addNewInsideH().setVal(STBorder.SINGLE); borders.addNewInsideV().setVal(STBorder.SINGLE); borders.addNewLeft().setVal(STBorder.SINGLE); borders.addNewRight().setVal(STBorder.SINGLE); borders.addNewTop().setVal(STBorder.SINGLE); /* * CTTblGrid tblgrid=table.addNewTblGrid(); * tblgrid.addNewGridCol().setW(new BigInteger("2000")); */ //getRows(); }
/** * add a new Row to the table * at position pos * @param row the row which should be added */ public boolean addRow(XWPFTableRow row, int pos){ if(pos >= 0 && pos <= tableRows.size()){ ctTbl.insertNewTr(pos); ctTbl.setTrArray(pos,row.getCtRow()); tableRows.add(pos, row); return true; } return false; }
/** * add a new Row to the table * * @param row the row which should be added */ public void addRow(XWPFTableRow row) { ctTbl.addNewTr(); ctTbl.setTrArray(getNumberOfRows() - 1, row.getCtRow()); tableRows.add(row); }
/** * add a new column for each row in this table */ public void addNewCol() { if (ctTbl.sizeOfTrArray() == 0) { createRow(); } for (int i = 0; i < ctTbl.sizeOfTrArray(); i++) { XWPFTableRow tabRow = new XWPFTableRow(ctTbl.getTrArray(i), this); tabRow.createCell(); } }
public static float[] computeColWidths( CTTbl table ) { CTTblGrid grid = table.getTblGrid(); List<CTTblGridCol> cols = getGridColList( grid ); int nbColumns = cols.size(); float[] colWidths = new float[nbColumns]; float colWidth = -1; int nbColumnsToIgnoreBefore = 0; for ( int i = nbColumnsToIgnoreBefore; i < colWidths.length; i++ ) { CTTblGridCol tblGridCol = cols.get( i ); colWidth = tblGridCol.getW().floatValue(); colWidths[i] = dxa2points( colWidth ); } return colWidths; }