How to use xwpftable in POI to merge cells (or apply colSpan) in Java?

Creating a table in POI is very simple, but its tutorial is very limited. I can't find a simple merged cell in the table that generates docx file

Solution

If you have created tables, rows within rows, and cells within rows, you can add gridspan to the cell properties:

if (cell.getCTTc().getTcPr() == null) cell.getCTTc().addNewTcPr();
if (cell.getCTTc().getTcPr().getGridSpan() == null) cell.getCTTc().getTcPr().addNewGridSpan();
cell.getCTTc().getTcPr().getGridSpan().setVal(2);

Note: cell is org apache. poi. xwpf. usermodel. XWPFTableCell.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>