JeecgBoot 單表數據導出多sheet實例


現在要導出格式如下:

 

實體如下:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM