easy poi 的,使用ExcelExportEntity生成多sheet的excel文件

pom.xml
<dependency>
	<groupId>cn.afterturn</groupId>
	<artifactId>easypoi-base</artifactId>
	<version>3.2.0</version>
</dependency>
<dependency>
	<groupId>cn.afterturn</groupId>
	<artifactId>easypoi-web</artifactId>
	<version>3.2.0</version>
</dependency>
<dependency>
	<groupId>cn.afterturn</groupId>
	<artifactId>easypoi-annotation</artifactId>
	<version>3.2.0</version>
</dependency>
代码
  try {
        	
     	List<Map<String,Object>> sheets = new ArrayList<Map<String,Object>>();
     	
     	for(int i = 0;i<10;i++) {
     		Map<String,Object> sheet = new HashMap<String,Object>();
         	
             List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();//构造对象等同于@Excel
             
             entity.add(new ExcelExportEntity("性别", "sex"));
             entity.add(new ExcelExportEntity("姓名", "name"));
             
             List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
             Map<String,Object> h1 = new HashMap<String,Object>();
             h1.put("name", "name" + i);
             h1.put("sex", "sex" +  i);
             Map<String,Object> h2 = new HashMap<String,Object>();
             h2.put("name", "name" +i+i);
             h2.put("sex", "sex" +i+i);
             list.add(h1);
             list.add(h2);
             
             sheet.put(NormalExcelConstants.CLASS, ExcelExportEntity.class);
             sheet.put(NormalExcelConstants.DATA_LIST, list);
             sheet.put(NormalExcelConstants.PARAMS, new ExportParams(null, "sheet"+i));
             sheet.put(NormalExcelConstants.MAP_LIST, entity);
             sheets.add(sheet);
     	}
     	
     	 Workbook workbook = new HSSFWorkbook();
     	 
     	 for(Map<String,Object> map : sheets) {
     		 ExcelExportService server = new ExcelExportService();
     		 ExportParams param = (ExportParams) map.get("params");
     		 @SuppressWarnings("unchecked")
	List<ExcelExportEntity> entity = (List<ExcelExportEntity>) map.get("mapList");
     		 Collection<?> data = (Collection<?>) map.get("data");
     		 server.createSheetForMap(workbook, param, entity, data);
     	 }

         FileOutputStream fos = new FileOutputStream("D:/ExcelExportForMap.tt.xls");
         workbook.write(fos);
         fos.close();
     } catch (FileNotFoundException e) {
         e.printStackTrace();
     } catch (IOException e) {
         e.printStackTrace();
     }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值