当前位置:网站首页>poi导出excel,行相同数据自动合并单元格
poi导出excel,行相同数据自动合并单元格
2022-04-23 05:38:00 【wyazyf】
/**
*excel行自动合并
*listData 待导出数据
*/
public void test(SXSSFSheet sheet,List<FanManagerExt> listData){
//备份上一条数据
FanManagerExt entityOld = new FanManagerExt();
for(int i=0;i<listData.size();i++){
//当前行数据
FanManagerExt entity= listData.get(i);
//实体字段集合(有序)
Field[] fields = entity.getClass().getDeclaredFields();
Field[] fieldOld = entityOld.getClass().getDeclaredFields();
for(int a=0;a<fields.length;a++){
fields[a].setAccessible(true);
fieldOld[a].setAccessible(true);
//将上下两行同列数据强制转换为字符串进行比较,相同设置单元格合并
try {
if(String.valueOf(fieldOld[a].get(entityOld)).equals(String.valueOf(fields[a].get(entity)))){
CellRangeAddress cra=new CellRangeAddress(i, i+1, a+1, a+1);
//在sheet里设置合并单元格
sheet.addMergedRegion(cra);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
//对象深拷贝
BeanUtils.copyProperties(entity,entityOld);
}
}
版权声明
本文为[wyazyf]所创,转载请带上原文链接,感谢
https://blog.csdn.net/wyazyf/article/details/120194495
边栏推荐
- catkin_ What did package do
- what is wifi6?
- Flutter 新一代圖形渲染器 Impeller
- Understand the relationship between promise async await
- Create a tabbar component under the components folder, which is public
- C语言——恶搞关机小程序
- Linear sieve method (prime sieve)
- STD:: String implements split
- Double click The jar package cannot run the solution
- String class understanding - final is immutable
猜你喜欢
Box collapse and margin collapse
Cross platform packaging of QT packaging program
Jiugong magic square - the 8th Lanqiao provincial competition - group C (DFS and comparison of all magic square types)
AcWing 836. Merge set (merge set)
Understand the relationship between promise async await
Data mining -- understanding data
3d slicer中拉直体的生成
Use of qwbengneview and qwebchannel.
Hongji cyclone RPA provides technical support for Guojin securities and realizes process automation in more than 200 business scenarios
Camera imaging + homography transformation + camera calibration + stereo correction
随机推荐
Differences between sea level anatomy and sea surface height anatomy
Pol / select / EPO
Formal parameters, local variables and local static variables
Sea Level Anomaly 和 Sea Surface Height Anomaly 的区别
Vscode settings JSON configuration
7-10 longest symmetric substring (25 points) (violence problem solution) C language
TypeScript interface & type 粗略理解
catkin_package到底干了什么
X86 assembly syntax: at & T and Intel
The title bar will be pushed to coincide with the status bar
Introduction to qqueue
QSslSocket::connectToHostEncrypted: TLS initialization failed
Executable program execution process
The QT debug version runs normally and the release version runs crash
Necessity of selenium preloading cookies
提升Facebook触及率和互动率攻略 | 智能客服帮您抓住用户的心
shell指令学习1
Edit, cancel, pull up menu
Membarrier (personal learning and understanding)
Batch import of orange single micro service