JeecgBoot 單表數據導出多sheet實例

現在要導出格式如下:

實體如下:

public class TestEntity{

    @Excel(name = "姓名", width = 15)
    private String username;
    
    @Excel(name = "年齡", width = 15)
    private int age;

.....省略後續getset

數據格式如下:

//多個map,對應了多個sheet
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();

for(int i=0;i<3;i++){
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("title",getExportParams("測試"+i));//表格title
    map.put("entity",TestEntity.class);//表格對應實體

    //數據封裝方式一:map數據,手動封裝ExcelExportEntity集合
    List<Map> ls=new ArrayList<Map> ();
    for(int j=0;j<10;j++){
        Map map = new HashMap();
        map1.put("name","李四"+j);
        map1.put("age",18+j);
        ls.add(map);
    }

   //數據封裝方式二:實體類
    List<TestEntity> ls=new ArrayList<TestEntity> ();
    for(int j=0;j<10;j++){
        TestEntity testEntity = new TestEntity();
        testEntity.setName("張三"+j);
        testEntity.setAge(18+j);
        ls.add(testEntity);
    }
    map.put("data", ls);
    listMap.add(map);
}

//導出參數
public static ExportParams getExportParams(String name) {
     //表格名稱,sheet名稱,導出版本 
    return  new ExportParams(name,name,ExcelType.XSSF);
}

調用ExcelExportUtil.exportExcel方法生成workbook

Workbook wb = ExcelExportUtil.exportExcel(listMap,ExcelType.XSSF);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章