使用EasyPoi导出Excel

 

Excel模板来自自己写死的一个excel模板,相当于是用户查询数据,数据填充到一个模板的Excel里,再导出Excel

 

 

/*创建模板*/
String a= request.getSession().getServletContext().getRealPath("/resource/河南能源化工集团安全监控系统联网系统瓦斯涌出异常信息表.xlsx");

获取模板

TemplateExportParams params=new TemplateExportParams(a);

获取查询数据,将数据放到map里面,自定义的excel的单元格里获取map的key值

List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
for(int i=0;i<list.size();i++){
Map<String, String> ma = new HashMap<String, String>();
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的配置

<!-- Excel 处理 根据用户输入进行对象处理 -->
<bean id="jeecgExcelView" class="org.jeecgframework.poi.excel.view.JeecgSingleExcelView" />
<bean id="jeecgTemplateExcelView" class="org.jeecgframework.poi.excel.view.JeecgTemplateExcelView" />
<bean id="jeecgTemplateWordView" class="org.jeecgframework.poi.excel.view.JeecgTemplateWordView" />
<bean id="jeecgMapExcelView" class="org.jeecgframework.poi.excel.view.JeecgMapExcelView" />

导出结果

 

posted @ 2018-11-12 16:49  自己好好想想吧  阅读(2849)  评论(0编辑  收藏  举报