Excel模板來自定義的一個excel模板,相當于是用戶查詢數據,數據填充到一個模板的Excel里,再導出Excel
/*創建模板*/
String a=request.getSession().getServletContext().getRealPath("/resource/河南能源化工集團安全監控系統聯網系統瓦斯涌出異常信息表.xlsx");
獲取模板
TemplateExportParams params=new TemplateExportParams(a);
獲取查詢數據,將數據放到map里面,自定義的excel的單元格里獲取map的key值
List> listMap = new ArrayList>();
for(int i=0;i
Map ma = new HashMap();
ma.put("xh", String.valueOf(i+1));
ma.put("mygs", list.get(i).getGs());
ma.put("kjmc", list.get(i).getMineName());
ma.put("dd", list.get(i).getLocation());
ma.put("zdz", list.get(i).getNowmaxvalue());
ma.put("zdzsk", list.get(i).getNowtime());
ma.put("three", list.get(i).getTheaybeforeValue());
ma.put("two", list.get(i).getTwodaysagoValue());
ma.put("one", list.get(i).getTheaybeforeValue());
ma.put("nowzdz", list.get(i).getNowmaxvalue());
listMap.add(ma);
}
map.put("listmap", listMap);
modelMap.put(TemplateExcelConstants.FILE_NAME, "河南能源化工集團安全監控系統聯網系統瓦斯涌出異常信息表"); //文件名
modelMap.put(TemplateExcelConstants.PARAMS, params);//參數
modelMap.put(TemplateExcelConstants.MAP_DATA, map);//數據
return TemplateExcelConstants.JEECG_TEMPLATE_EXCEL_VIEW;//view名稱
SpringWeb中,需要在spring-mvc.xml中引入處理Excel的配置
導出結果