我正在尝试将边框添加到合并的单元格,但使用下面的代码行是不可能的:
XWPFDocument document = new XWPFDocument();
XWPFTable table = document.createTable(1, 8);
CTTblBorders borders = table.getCTTbl().getTblPr().addNewTblBorders();
borders.addNewBottom().setVal(STBorder.THICK);
borders.addNewLeft().setVal(STBorder.NONE);
borders.addNewRight().setVal(STBorder.NONE);
borders.addNewTop().setVal(STBorder.THICK);
borders.addNewInsideV().setVal(STBorder.THICK);
table.getCTTbl().getTblPr().setTblBorders(borders);
table.setWidth(1440);
for (int col = 0 ; col < 8; col++) {
CTTblWidth tblWidth = table.getRow(0).getCell(col).getCTTc().addNewTcPr().addNewTcW();
tblWidth.setW(BigInteger.valueOf(1440));
//STTblWidth.DXA is used to specify width in twentieths of a point.
tblWidth.setType(STTblWidth.DXA);
}
**mergeCellHorizontally(table, 0, 0, 1);**
XWPFTableCell cell = table.getRow(0).getCell(1);
CTTcPr ctTcPr = cell.getCTTc().getTcPr();
CTTcBorders ctTcBorders = ctTcPr.addNewTcBorders();
ctTcBorders.addNewRight().setVal(STBorder.NONE);
ctTcBorders.addNewBottom().setVal(STBorder.NONE);