上图列都挤在一起了。
自己试了一下上面的方式,不管用,根本不会生效。
在设置表格总宽度的方法里加:
CTTblPr tblPr = ttbl.getTblPr() == null ? ttbl.addNewTblPr() : ttbl.getTblPr();
CTTblLayoutType t = tblPr.isSetTblLayout()?tblPr.getTblLayout():tblPr.addNewTblLayout();
t.setType(STTblLayoutType.FIXED);//使布局固定,不随内容改变宽度
昨天试了一下,可行
大佬 最后怎么解决的?
public static int[] COLUMN_WIDTHS = new int[] {1504,1504,1504,1504,1504,1504};
setTableGridCol(table, COLUMN_WIDTHS);
/**
* @Description: 设置表格列宽
*/
public void setTableGridCol(XWPFTable table, int[] colWidths) {
CTTbl ttbl = table.getCTTbl();
CTTblGrid tblGrid = ttbl.getTblGrid() != null ? ttbl.getTblGrid()
: ttbl.addNewTblGrid();
for (int j = 0, len = colWidths.length; j < len; j++) {
CTTblGridCol gridCol = tblGrid.addNewGridCol();
gridCol.setW(new BigInteger(String.valueOf(colWidths[j])));
}
}