如何在Java中使用POI要XWPFTable合并单元格(或申请合并单元格)? [英] How to merge cells ( or apply colspan) using XWPFTable in POI in Java?

查看:2297
本文介绍了如何在Java中使用POI要XWPFTable合并单元格(或申请合并单元格)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.

推荐答案

如果您已经创建表,行一个行内的表和单元格内,你可以添加到网格扩展单元格属性:

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合并单元格(或申请合并单元格)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆