程序员

JeecgBoot 单表数据导出多sheet实例

作者:admin 2021-04-09 我要评论

现在要导出格式如下: 实体如下: public classTestEntity{ @Excel( name = 姓名 ,width=15) privateStringusername; @Excel( name = 年龄 ,width=15) private i...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

现在要导出格式如下:


实体如下:

  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. public static ExportParams getExportParams(String name) { 
  31.      //表格名称,sheet名称,导出版本  
  32.     return  new ExportParams(name,name,ExcelType.XSSF); 

调用ExcelExportUtil.exportExcel方法生成workbook

  1. Workbook wb = ExcelExportUtil.exportExcel(listMap,ExcelType.XSSF); 

本文转载自网络,原文链接:https://www.toutiao.com/i6937467263293424141/

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 四两拨千斤——你不知道的VScode编码Ty

    四两拨千斤——你不知道的VScode编码Ty

  • 我是如何在 Vue 项目中做代码分割的

    我是如何在 Vue 项目中做代码分割的

  • position:sticky 粘性定位的几种巧妙应

    position:sticky 粘性定位的几种巧妙应

  • 从零到一搭建React组件库

    从零到一搭建React组件库

腾讯云代理商
海外云服务器