使用Map方式导出示例Demo:
@RequestMapping(params = "exportXls")
public String exportXls(ModelMap modelMap,HttpServletRequest request ){
modelMap.put(MapExcelConstants.ENTITY_LIST, newAddExcel());
modelMap.put(MapExcelConstants.MAP_LIST, sourceData());
modelMap.put(MapExcelConstants.FILE_NAME, "新增数据统计");
modelMap.put(MapExcelConstants.PARAMS, new ExportParams("新增数据统计", "导出人:" + ResourceUtil.getSessionUser().getRealName(), "导出信息"));
return MapExcelConstants.JEECG_MAP_EXCEL_VIEW;
}
private List<ExcelExportEntity> newAddExcel(){
List<ExcelExportEntity> entityList = new ArrayList<>();
ExcelExportEntity xh = new ExcelExportEntity("序号","nu",30);
xh.setFormat("isAddIndex");
entityList.add(xh);
entityList.add(new ExcelExportEntity("新增时间","clrsj",30));
entityList.add(new ExcelExportEntity("案件名称","cajmc",50));
entityList.add(new ExcelExportEntity("案件类型","cajlx",30));
entityList.add(new ExcelExportEntity("案件编号","cajbh",40));
entityList.add(new ExcelExportEntity("当事人姓名","cdsrxm",25));
entityList.add(new ExcelExportEntity("性别","sex",15));
entityList.add(new ExcelExportEntity("当事人身份证号","cdsrsfz",40));
entityList.add(new ExcelExportEntity("代保管金额(元)","cdbgje",50));
entityList.add(new ExcelExportEntity("代保管物品(件)","cdbgwp",30));
return entityList;
}
private List<Map<String,String>> sourceDate(){
Map<String,String> map = new LinkedHashMap<>();
map.put("clrsj","2018-07-23 11:20:30");
map.put("cajmc","李刚儿子撞人案");
Map<String,String> map2 = new LinkedHashMap<>();
map2.put("clrsj","2018-07-23 11:24:30");
map2.put("cajmc","黄志慧打人案");
List<Map<String,String>> newData = new ArrayList<>();
newData.add(map);
newData.add(map2);
return newData;
}
效果如下 :
序号是自动增加,关键是设置为:
ExcelExportEntity xh = new ExcelExportEntity("序号","nu",30);
xh.setFormat("isAddIndex");
entityList.add(xh);
了解更多easypoi说明文档:http://easypoi.mydoc.io/