合并单元格的方法
2021
04.14

合并单元格的方法: 

sheet.addMergedRegion("起始行", "起始列", "终止行", "终止列");

合并示例:

//表头信息

HSSFRow row1= sheet.createRow(0);

cell = row1.createCell((short) 0);

cell.setCellValue("");

sheet.addMergedRegion(new Region((short)0, (short) 0, (short)0, (short) 0));

cell = row1.createCell((short) 1); cell.setCellValue("时间");

sheet.addMergedRegion(new Region((short)0, (short) 1, (short)0, (short) 2));



HSSFRow row2= sheet.createRow(1);

cell = row2.createCell((short) 0);

cell.setCellValue("序号");

sheet.addMergedRegion(new Region((short)1, (short) 0, (short)1, (short) 0));

cell = row2.createCell((short) 1); cell.setCellValue("起始时间");

sheet.addMergedRegion(new Region((short)1, (short) 1, (short)1, (short) 1));

cell = row2.createCell((short) 2); cell.setCellValue("终止时间");

sheet.addMergedRegion(new Region((short)1, (short) 2, (short)1, (short) 2));



 

运行结果,得到的 Excel 表如下所示: 

 

 

 

文件样式可在导出后自行添加


热门文章
1
Java实现html页面抓取转PDF
1207浏览 2021-04-13 17:09
2
对接父子级数据的添加或修改逻辑
1174浏览 2021-04-21 09:47
3
Mysql常用sql语句
1172浏览 2021-04-20 10:46
4
通过微信接口获取code
1165浏览 2021-04-14 09:26
5
vue 页面按钮点击复制内容
1164浏览 2021-04-21 09:42
6
Linux安装中文字体
1124浏览 2021-04-13 17:14
7
vue中数组去重的实现
1086浏览 2021-04-14 09:20
8
合并单元格的方法
1080浏览 2021-04-14 09:23
9
Nginx如何配置重定向
1078浏览 2021-04-14 09:09
10
互联网文明颠覆你的认知
895浏览 2020-12-02 15:47