JeecgBoot 單表數(shù)據(jù)導(dǎo)出多sheet實(shí)例
作者:JEECG
本篇給大家介紹JeecgBoot 單表數(shù)據(jù)導(dǎo)出多sheet實(shí)例,希望對(duì)你有所幫助!
現(xiàn)在要導(dǎo)出格式如下:

實(shí)體如下:
- public class TestEntity{
- @Excel(name = "姓名", width = 15)
- private String username;
- @Excel(name = "年齡", width = 15)
- private int age;
- .....省略后續(xù)getset
數(shù)據(jù)格式如下:
- //多個(gè)map,對(duì)應(yīng)了多個(gè)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("測(cè)試"+i));//表格title
- map.put("entity",TestEntity.class);//表格對(duì)應(yīng)實(shí)體
- //數(shù)據(jù)封裝方式一:map數(shù)據(jù),手動(dòng)封裝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);
- }
- //數(shù)據(jù)封裝方式二:實(shí)體類
- 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);
- }
- //導(dǎo)出參數(shù)
- public static ExportParams getExportParams(String name) {
- //表格名稱,sheet名稱,導(dǎo)出版本
- return new ExportParams(name,name,ExcelType.XSSF);
- }
調(diào)用ExcelExportUtil.exportExcel方法生成workbook
- Workbook wb = ExcelExportUtil.exportExcel(listMap,ExcelType.XSSF);
【編輯推薦】
責(zé)任編輯:姜華
來(lái)源:
今日頭條