我需要插入一个表格,向表格中写入内容,表格中存在合并的表格列,我希望在表格合并之后也能保持垂直居中,我该怎么做呢?
这是我的代码:
public static void main(String[] args) throws Exception {
Document doc = new Document("test.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.startTable();
Cell cell;
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
cell = builder.insertCell();
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.write("垂直居中");
cell.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
cell = builder.insertCell();
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.write("");
cell.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
cell = builder.insertCell();
builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
builder.write("总计");
cell.getCellFormat().setHorizontalMerge(CellMerge.NONE);
builder.endRow();
builder.endTable();
doc.save("result.docx");
}