如何在Java中的POI中使用XWPFTable合并单元格(或应用colspan)? [英] How to merge cells (or apply colspan) using XWPFTable in POI in Java?
本文介绍了如何在Java中的POI中使用XWPFTable合并单元格(或应用colspan)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在poi中创建一个表非常简单,但它的教程非常有限,我找不到一个可以在生成docx文件的表中创建一个简单的合并单元格。
Creating a table in poi was quite easy but it has very limited tutorials and I cannot find one that can create a simple merged cell in a table in generating a docx file.
推荐答案
如果您已创建表,行内的行和行内的单元格,则可以将gridSpan添加到单元格属性:
If you have created table, row inside a table and cell inside a row, you can add gridSpan to 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);
注意:单元格是org.apache.poi.xwpf.usermodel.XWPFTableCell。
Note: cell is org.apache.poi.xwpf.usermodel.XWPFTableCell.
这篇关于如何在Java中的POI中使用XWPFTable合并单元格(或应用colspan)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文