下载excel表格工具类

时间:2021-08-20 09:58:04
【文件属性】:
文件名称:下载excel表格工具类
文件大小:6KB
文件格式:JAVA
更新时间:2021-08-20 09:58:04
excel 下载excel表格工具类。controller:@RequestMapping(value = "/form", method = RequestMethod.GET) public ModelAndView downloadForm(HttpServletRequest request) { try {List> listLog = maintainlogService.selectListByDownload(memberId,date,keyword);//查询数据库中的数据 //excel数据 List<Object> listData = new ArrayList<Object>(); if (null != listLog && listLog.size()>0){ BigDecimal totalPrice = new BigDecimal("0.0");//总金额 int count = 0;//总笔数 for(Map map : listLog){ totalPrice = totalPrice.add(new BigDecimal(map.get("maintainPrice").toString())); count ++; List<Object> data = new ArrayList<Object>(); data.add(map.get("addDate")); data.add(map.get("carUserName")); data.add(map.get("telPhone")); data.add(map.get("licence")); data.add(map.get("carBrand")); data.add(map.get("carQuestion")); data.add(map.get("maintainConten")); data.add(map.get("maintainPrice")); data.add(map.get("maintainDate")); if (StringUtils.isEmpty(memberId)){ data.add(map.get("mainName")); data.add(map.get("mainPhone")); } listData.add(data); } //excel表格最后一行 List<Object> footer = new ArrayList<Object>(); footer.add("总计:"); footer.add(count+"笔"); footer.add(totalPrice.doubleValue()+"元"); listData.add(footer); } //excel 头部 Map mapRow = new LinkedHashMap(); mapRow.put("日期",20 * 256); mapRow.put("车主",20 * 256); mapRow.put("车主电话",20 * 256); mapRow.put("车牌",20 * 256); mapRow.put("汽车品牌",20 * 256); mapRow.put("车辆问题",20 * 256); mapRow.put("维修内容",40 * 256); mapRow.put("维修金额",20 * 256); mapRow.put("维修日期",20 * 256); if (StringUtils.isEmpty(memberId)){ mapRow.put("维修商",30 * 256); mapRow.put("维修商电话",30 * 256); } //设置excel Map result = new HashMap(); result.put("excelTitle", date+"月信息明细"); result.put("excelName", date+"月信息明细数据"); result.put("titleMap", mapRow); result.put("dataList", listData); ExcelView excelView = new ExcelView(); return new ModelAndView(excelView, result); } catch (Exception e) { e.printStackTrace(); } return new ModelAndView(); js:function download(){ var date = $("#stime").val(); var keyword = $("#keyword").val(); [removed].href="<%=basePath%>/admin/mainInfo/form?date="+date+"&keyword;="+encodeURI(keyword); }

网友评论