使用 Apache POI 合并 Excel 中的单元格 [英] Merging cells in Excel using Apache POI

查看:91
本文介绍了使用 Apache POI 合并 Excel 中的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有其他方法可以使用 Apache POI 库合并 Excel 中的单元格?

Is there any other way to merge cells in Excel using Apache POI library?

我正在尝试使用以下方法,但它不起作用

I was trying using the following, but its not working

// selecting the region in Worksheet for merging data
CellRangeAddress region = CellRangeAddress.valueOf("A" + rowNo + ":D"
            + rowNo);

// merging the region
sheet1.addMergedRegion(region);

推荐答案

可以使用 sheet.addMergedRegion(rowFrom,rowTo,colFrom,colTo);

example sheet.addMergedRegion(new CellRangeAddress(1,1,1,4)); 将从 B2 合并到 E2.请记住,它是基于零的索引(例如 POI 版本 3.12).

example sheet.addMergedRegion(new CellRangeAddress(1,1,1,4)); will merge from B2 to E2. Remember it is zero based indexing (ex. POI version 3.12).

详情请参阅BusyDeveloper's Guide

这篇关于使用 Apache POI 合并 Excel 中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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