随笔 - 408  文章 - 4 评论 - 11 阅读 - 30万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

现在要导出格式如下:

 

实体如下:

复制代码
1 public class TestEntity{
2 
3     @Excel(name = "姓名", width = 15)
4     private String username;
5     
6     @Excel(name = "年龄", width = 15)
7     private int age;
8 
9 .....省略后续getset
复制代码

 

数据格式如下:

复制代码
 1 //多个map,对应了多个sheet
 2 List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
 3 
 4 for(int i=0;i<3;i++){
 5     Map<String, Object> map = new HashMap<String, Object>();
 6     map.put("title",getExportParams("测试"+i));//表格title
 7     map.put("entity",TestEntity.class);//表格对应实体
 8 
 9     //数据封装方式一:map数据,手动封装ExcelExportEntity集合
10     List<Map> ls=new ArrayList<Map> ();
11     for(int j=0;j<10;j++){
12         Map map = new HashMap();
13         map1.put("name","李四"+j);
14         map1.put("age",18+j);
15         ls.add(map);
16     }
17 
18    //数据封装方式二:实体类
19     List<TestEntity> ls=new ArrayList<TestEntity> ();
20     for(int j=0;j<10;j++){
21         TestEntity testEntity = new TestEntity();
22         testEntity.setName("张三"+j);
23         testEntity.setAge(18+j);
24         ls.add(testEntity);
25     }
26     map.put("data", ls);
27     listMap.add(map);
28 }
29 
30 //导出参数
31 public static ExportParams getExportParams(String name) {
32      //表格名称,sheet名称,导出版本 
33     return  new ExportParams(name,name,ExcelType.XSSF);
34 }
复制代码
 

调用ExcelExportUtil.exportExcel方法生成workbook

1 Workbook wb = ExcelExportUtil.exportExcel(listMap,ExcelType.XSSF);
posted on   zhangdaiscott  阅读(1050)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示