JeecgBoot 单表数据导出多sheet实例

数据库
本篇给大家介绍JeecgBoot 单表数据导出多sheet实例,希望对你有所帮助!

[[386529]]

 现在要导出格式如下:


实体如下:

  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); 

 【编辑推荐】

 

责任编辑:姜华 来源: 今日头条
相关推荐

2011-06-29 14:01:30

多数据库实例效率

2010-04-02 13:46:30

Oracle数据导出

2022-12-28 08:17:36

数据库数据导出

2010-04-22 10:16:43

2010-06-02 11:34:23

MySQL 数据库导入

2010-03-30 09:01:01

Oracle数据

2010-11-11 11:00:06

sql server遍

2019-10-12 16:15:13

MySQL数据库多实例

2010-11-29 13:22:45

sybase数据表

2010-09-10 13:45:18

SQLCOUNT()函数

2009-07-02 09:40:17

JSP导出Oracle

2017-07-04 15:45:30

数据库RACWindows平台

2013-11-26 16:32:03

MYSQLMYSQL配置

2009-11-06 14:25:20

Oracle创建用户表

2010-04-30 14:47:56

Oracle表

2021-06-29 08:12:22

MySQL数据分页数据库

2010-10-15 10:14:09

Mysql建表

2021-02-27 09:30:16

PythonExcelSheet

2016-10-09 09:37:49

javascript单例模式

2010-04-23 17:55:25

Oracle数据库
点赞
收藏

51CTO技术栈公众号