/** * 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); }
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(); }
private static CTTblPr getTblPr(XWPFTable table) { CTTblPr tblPr = table.getCTTbl().getTblPr(); if (null == tblPr) { tblPr = table.getCTTbl().addNewTblPr(); } return tblPr; }
/** * 表格设置宽度,每列平均分布 * * @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()); } }
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);
/** * 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); }
private CTTblPr getTrPr() { return (ctTbl.getTblPr() != null) ? ctTbl.getTblPr() : ctTbl .addNewTblPr(); }
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);
CTTblPr ctTblPr = ctTbl.addNewTblPr(); CTTblLayoutType layoutType = ctTblPr.addNewTblLayout(); layoutType.setType(STTblLayoutType.FIXED);
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(); }
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(); }