当前位置:网站首页>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
边栏推荐
- 创建进程内存管理copy_mm - 进程与线程(九)
- Introduction to data security -- detailed explanation of database audit system
- open3d材质设置参数分析
- Qwebsocket communication
- C, class library
- Xiuxian real world and game world
- Utf8 to STD: string and STD: string to utf8
- QT drawpixmap and DrawImage blur problem
- World and personal development
- Interview Basics
猜你喜欢

what is wifi6?

AcWing 836. Merge set (merge set)

Camera imaging + homography transformation + camera calibration + stereo correction

‘EddiesObservations‘ object has no attribute ‘filled‘

Transposed convolution

Hongji cyclone RPA provides technical support for Guojin securities and realizes process automation in more than 200 business scenarios

QSS, qdateedit, qcalendarwidget custom settings

Understand the relationship between promise async await

Various situations of data / component binding

C# ,类库
随机推荐
Use pagoda + Xdebug + vscode to debug code remotely
Find the number of "blocks" in the matrix (BFS)
‘EddiesObservations‘ object has no attribute ‘filled‘
Establish excel bookkeeping book through setting context menu
可執行程序執行流程
Parsing of string class intern() method
Relative reference and absolute reference of Excel
Frequently asked interview questions - 3 (operating system)
Wbpack configuring production development environment
The title bar will be pushed to coincide with the status bar
Reading notes of modern methods of C language programming
What financial products will benefit during May Day?
js数字大写方法
创建进程内存管理copy_mm - 进程与线程(九)
Sword finger offer II 022 The entry node of the link in the linked list
五一劳动节期间什么理财产品会有收益?
CMake基础教程(39)pkgconfig
Create cells through JS (while loop)
Differences between auto and decltype inference methods (learning notes)
Flutter 新一代图形渲染器 Impeller