当前位置:网站首页>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
边栏推荐
- 使用宝塔+xdebug+vscode远程调试代码
- Introduction to data security -- detailed explanation of database audit system
- 世界与个人发展
- QSS, qdateedit, qcalendarwidget custom settings
- Radar equipment (greedy)
- Similarities and differences between vector and array (notes)
- 3d slicer中拉直体的生成
- Relative reference and absolute reference of Excel
- The QT debug version runs normally and the release version runs crash
- Breadth first search topics (BFS)
猜你喜欢
C language - Spoof shutdown applet
Batch import of orange single micro service
On the use of constant pointer and pointer constant -- exercise (record)
Box collapse and margin collapse
Flutter 新一代图形渲染器 Impeller
Data mining -- understanding data
弘玑|数字化时代下,HR如何进行自我变革和组织变革?
Arithmetic and logical operations
‘EddiesObservations‘ object has no attribute ‘filled‘
If I am PM's performance, movie VR ticket purchase display
随机推荐
Golang通过exec模块实现Ping连通性检测案例
引航成长·匠心赋能——YonMaster开发者培训领航计划全面开启
Wbpack configuring production development environment
The 8th Blue Bridge Cup 2017 - frog jumping cup
[untitled] Notepad content writing area
[triangle Yang Hui triangle printing odd even cycle JS for break cycle]
7-10 longest symmetric substring (25 points) (violence problem solution) C language
Branch and loop statements
Deep learning object detection
50 SQL exercises, answers and detailed analysis
橙单微服务之批量导入
js数字大写方法
STL function library
Xiuxian real world and game world
AcWing 1096. Detailed notes of Dungeon Master (3D BFS) code
SQL statement simple optimization
弘玑Cyclone RPA为国金证券提供技术支撑,超200个业务场景实现流程自动化
巴普洛夫与兴趣爱好
Frequently asked interview questions - 2 (computer network)
Camera imaging + homography transformation + camera calibration + stereo correction