我使用下面的代码在xwpf的Apache Poi中创建了一个表:
XWPFTable table = doc.createTable(Countrows1+1,4);
table.getCTTbl().getTblPr().unsetTblBorders();
table.setInsideHBorder(XWPFTable.XWPFBorderType.DASHED, 0,0,null);
table.setInsideVBorder(XWPFTable.XWPFBorderType.DASHED,0,0, null);
/* table header */
table.getRow(0).getCell(0).setText("Column1");
table.getRow(0).getCell(1).setText("Column2");
table.getRow(0).getCell(2).setText("Column3");
table.getRow(0).getCell(3).setText("Column");
/* other rows to be populed here*/我找不到任何方法,我们可以用来对齐表格到页面的左边,中间或右边的页面.Is有什么办法做到这一点吗?
第一行的内容也应该是粗体的。有没有什么方法可以将头部设置为粗体?
发布于 2015-08-23 03:06:08
您可以使用以下函数对齐表
public void setTableAlignment(XWPFTable table, STJc.Enum justification) {
CTTblPr tblPr = table.getCTTbl().getTblPr();
CTJc jc = (tblPr.isSetJc() ? tblPr.getJc() : tblPr.addNewJc());
jc.setVal(justification);
}发布于 2018-02-03 05:32:48
下面的代码适用于我:
public void setTableAlign(XWPFTable table,ParagraphAlignment align) {
CTTblPr tblPr = table.getCTTbl().getTblPr();
CTJc jc = (tblPr.isSetJc() ? tblPr.getJc() : tblPr.addNewJc());
STJc.Enum en = STJc.Enum.forInt(align.getValue());
jc.setVal(en);
}你可以像这样调用方法:
XWPFTable table = documento.createTable();
setTableAlign(table, ParagraphAlignment.CENTER);https://stackoverflow.com/questions/31406232
复制相似问题