网站空间那个好,优秀网页设计案例欣赏,南充房产信息网官网,佛山网站建设公司3lue用poi导出Excel表格#xff0c;需要配置很多东西#xff0c;也比较麻烦#xff0c;这里使用poi的封装easypoi#xff0c;可以快速配置#xff0c;实现Excel或者word文件的导出。这里我们结合SpringMVC开发easypoi。1#xff0c;导入以下3个.jar包:这里是springMVC和easyp…用poi导出Excel表格需要配置很多东西也比较麻烦这里使用poi的封装easypoi可以快速配置实现Excel或者word文件的导出。这里我们结合SpringMVC开发easypoi。1导入以下3个.jar包:这里是springMVC和easypoi所需的jar包主要是easypoi-base和easypoi-web其它都是关联所需的jar包我们需要commons-lang3.jar包开始使用commons-lang2.6版本会出现错误。2spring-mvc.xml配置如下classorg.springframework.web.servlet.view.BeanNameViewResolver p:order01.ExcelExportUtil Excel导出(普通导出,模板导出)2.ExcelImportUtil Excel导入3.WordExportUtil Word导出(只支持docx ,doc版本poi3 Controller导入方式可以根据映射关系通过注解字段名符合导入如下例public class RechannelreportEntity implements java.io.Serializable {/**id*/private java.lang.Integer id;/**amount*/Excel(nameamount)private java.lang.Integer amount;/**amounts*/Excel(nameamounts)private java.lang.Integer amounts;/**counts*/Excel(namecounts)private java.lang.Integer counts;/**date*/Excel(namedate,format yyyy-MM-dd)private java.util.Date date;/**username*/.......SuppressWarnings(unchecked)RequestMapping(params importExcel, method RequestMethod.POST)ResponseBodypublic AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {AjaxJson j new AjaxJson();MultipartHttpServletRequest multipartRequest (MultipartHttpServletRequest) request;Map fileMap multipartRequest.getFileMap();for (Map.Entry entity : fileMap.entrySet()) {MultipartFile file entity.getValue();// 获取上传文件对象ImportParams params new ImportParams();params.setTitleRows(2);params.setHeadRows(1);params.setNeedSave(true);try {List listRechannelreportEntitys ExcelImportUtil.importExcel(file.getInputStream(),RechannelreportEntity.class,params);for (RechannelreportEntity rechannelreport : listRechannelreportEntitys) {rechannelreportService.save(rechannelreport);}j.setMsg(文件导入成功);} catch (Exception e) {j.setMsg(文件导入失败);logger.error(ExceptionUtil.getExceptionMessage(e));}finally{try {file.getInputStream().close();} catch (IOException e) {e.printStackTrace();}}}return j;导出方式一可以自定义输出字段并赋值RequestMapping(params exportXls2)public String string2(RechannelreportEntity rechannelreport,HttpServletRequest request,HttpServletResponse response, DataGrid dataGrid,ModelMap modelMap) {//searchColumsundefinedsqlbuilderusernameCL007date_begin2017-01-17date_end2017-01-17List entityList new ArrayList();entityList.add(new ExcelExportEntity(日期, cou1, 15));entityList.add(new ExcelExportEntity(渠道号, cou2, 15));entityList.add(new ExcelExportEntity(原始金额, cou3, 15));entityList.add(new ExcelExportEntity(扣量金额, cou4, 15));entityList.add(new ExcelExportEntity(结算金额, cou5, 15));//这边的getData2 方法是对 MapExcelConstants.MAP_LIST进行赋值List dataResult getData2(getDateGrid(rechannelreport, request));modelMap.put(MapExcelConstants.ENTITY_LIST, entityList);modelMap.put(MapExcelConstants.MAP_LIST, dataResult);modelMap.put(MapExcelConstants.FILE_NAME, DateUtils.formatDate(new Date()) 数据);Date now new Date();modelMap.put(NormalExcelConstants.PARAMS, new ExportParams(rechannelreport.getUsername() 对账单详情, 导出日期: DateUtils.formatDate(new Date()) , 导出信息));return MapExcelConstants.JEECG_MAP_EXCEL_VIEW;}导出方式二根据实体映射现实字段ExcelTarget(courseEntity)public class CourseEntity implements java.io.Serializable {/** 主键 */ private String id;/** 课程名称 */ Excel(name 课程名称, orderNum 1, needMerge true)private String name;/** 老师主键 */ ExcelEntity(id yuwen)ExcelVerify()private TeacherEntity teacher;/** 老师主键 */ ExcelEntity(id shuxue)private TeacherEntity shuxueteacher;ExcelCollection(name 选课学生, orderNum 4)private List students;RequestMapping(params exportXls)public String exportXls(CourseEntity course,HttpServletRequest request,HttpServletResponse response, DataGrid dataGrid,ModelMap map) {CriteriaQuery cq new CriteriaQuery(CourseEntity.class, dataGrid);org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, course, request.getParameterMap());List courses this.courseService.getListByCriteriaQuery(cq,false);map.put(NormalExcelConstants.FILE_NAME,用户信息);map.put(NormalExcelConstants.CLASS,CourseEntity.class);map.put(NormalExcelConstants.PARAMS,new ExportParams(课程列表, 导出人:Jeecg,导出信息));map.put(NormalExcelConstants.DATA_LIST,courses);return NormalExcelConstants.JEECG_EXCEL_VIEW;}