使用easypoi以map方式匯出Excel序號自增的問題
使用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);