/** * 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); }
/** * 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; }
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()); } }
/** * 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); }
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++){
public static CTTblPr getTblPr( XWPFTable table ) { CTTbl tbl = table.getCTTbl(); if ( tbl != null ) { return tbl.getTblPr(); } return null; }
public static CTTblPr getTblPr( XWPFTable table ) { CTTbl tbl = table.getCTTbl(); if ( tbl != null ) { return tbl.getTblPr(); } return null; }
public CTTblPr getTblPr( XWPFTable table ) { return table.getCTTbl().getTblPr(); }
public CTTblPr getTblPr( XWPFTable table ) { return table.getCTTbl().getTblPr(); }
/** * 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; }
/** * 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; }
CTTbl table = poiTable.getCTTbl(); CTTblPr pr = table.getTblPr(); CTTblWidth tblW = pr.getTblW(); tblW.setW(BigInteger.valueOf(5000)); tblW.setType(STTblWidth.PCT); pr.setTblW(tblW); table.setTblPr(pr);
/** * Returns table width of teh XWPF table. * * @param table * @return */ public static TableWidth getTableWidth( XWPFTable table ) { float width = 0; boolean percentUnit = false; CTTblPr tblPr = table.getCTTbl().getTblPr(); if ( tblPr.isSetTblW() ) { CTTblWidth tblWidth = tblPr.getTblW(); return getTableWidth( tblWidth ); } return new TableWidth( width, percentUnit ); }
/** * Returns table width of teh XWPF table. * * @param table * @return */ public static TableWidth getTableWidth( XWPFTable table ) { float width = 0; boolean percentUnit = false; CTTblPr tblPr = table.getCTTbl().getTblPr(); if ( tblPr.isSetTblW() ) { CTTblWidth tblWidth = tblPr.getTblW(); return getTableWidth( tblWidth ); } return new TableWidth( width, percentUnit ); }
private void applyStyles( XWPFTable ele, IStylableElement<XWPFTable> element ) { CTString tblStyle = ele.getCTTbl().getTblPr().getTblStyle(); Style style; if ( tblStyle != null ) { style = styleEngine.getStyle( tblStyle.getVal() ); } else { style = styleEngine.getDefaultStyle(); } element.applyStyles( ele, style ); }
@Override protected Object startVisitTable( XWPFTable table, float[] colWidths, Object tableContainer ) throws Exception { // 1) create attributes // 1.1) Create class attributes. AttributesImpl attributes = createClassAttribute( table.getStyleID() ); // 1.2) Create "style" attributes. CTTblPr tblPr = table.getCTTbl().getTblPr(); CSSStyle cssStyle = getStylesDocument().createCSSStyle( tblPr ); if(cssStyle != null) { cssStyle.addProperty(CSSStylePropertyConstants.BORDER_COLLAPSE, CSSStylePropertyConstants.BORDER_COLLAPSE_COLLAPSE); } attributes = createStyleAttribute( cssStyle, attributes ); // 2) create element startElement( TABLE_ELEMENT, attributes ); return null; }
@Override protected Object startVisitTable( XWPFTable table, float[] colWidths, Object tableContainer ) throws Exception { // 1) create attributes // 1.1) Create class attributes. AttributesImpl attributes = createClassAttribute( table.getStyleID() ); // 1.2) Create "style" attributes. CTTblPr tblPr = table.getCTTbl().getTblPr(); CSSStyle cssStyle = getStylesDocument().createCSSStyle( tblPr ); if(cssStyle != null) { cssStyle.addProperty(CSSStylePropertyConstants.BORDER_COLLAPSE, CSSStylePropertyConstants.BORDER_COLLAPSE_COLLAPSE); } attributes = createStyleAttribute( cssStyle, attributes ); // 2) create element startElement( TABLE_ELEMENT, attributes ); return null; }