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