如下图1所示的表格样式,
如下图2中的代码:
我需要判断单元格与单元格的值是否相等,相等则合并,不相等则不合并。
求急啊, 望大神帮助, 谢谢!!!
poi动态合并单元格,判断单元格与单元格的值相等则合并
答案:2 悬赏:60
解决时间 2021-04-18 08:01
- 提问者网友:熱戀丶瘋
- 2021-04-17 20:30
最佳答案
- 二级知识专家网友:滚刀废物浮浪人
- 2021-04-17 21:47
添加区域,合并单元格
[c-sharp] view plaincopyprint?
1.region region = new region((short)rowfrom,(short)columnfrom,(short)rowto
2.(short)columnto);//合并从第rowfrom行columnfrom列
3.sheet.addmergedregion(region);// 到rowto行columnto的区域
4.//得到所有区域
5.sheet.getnummergedregions()
[c-sharp] view plaincopyprint?
1.region region = new region((short)rowfrom,(short)columnfrom,(short)rowto
2.(short)columnto);//合并从第rowfrom行columnfrom列
3.sheet.addmergedregion(region);// 到rowto行columnto的区域
4.//得到所有区域
5.sheet.getnummergedregions()
全部回答
- 1楼网友:两不相欠
- 2021-04-17 22:45
//poi-3.7.jar
public void getCombineCell(HSSFSheet sheet, List list) {
// 获得一个 sheet 中合并单元格的数量
int sheetmergerCount = sheet.getNumMergedRegions();
// 遍历合并单元格
for (int i = 0; i < sheetmergerCount; i++) {
// 获得合并单元格加入list中
CellRangeAddress ca = sheet.getMergedRegion(i);
list.add(ca);
}
}
public static Boolean isCombineCell(List listCombineCell,
HSSFCell cell, HSSFSheet sheet) {
int firstC = 0;
int lastC = 0;
int firstR = 0;
int lastR = 0;
for (CellRangeAddress ca : listCombineCell) {
// 获得合并单元格的起始行, 结束行, 起始列, 结束列
firstC = ca.getFirstColumn();
lastC = ca.getLastColumn();
firstR = ca.getFirstRow();
lastR = ca.getLastRow();
if (cell.getColumnIndex() <= lastC&& cell.getColumnIndex()>= firstC) {
if (cell.getRowIndex() <= lastR && cell.getRowIndex() >= firstR) {
return true;
}
}
}
return false;
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯