没有service方法,请问controller和jsp页面如何写,另外报表模板放在webapp/admin/excel下
1条回答 默认 最新
- 是星星总会发光 2016-04-28 03:41关注
用poi
/**
* 导出exec
* @param request
* @param response
* @param model
* @return
* @throws UnsupportedEncodingException
*/
@RequestMapping(value = "importExec", method = RequestMethod.GET)
@ResponseBody
public String importExec(HttpServletRequest request, HttpServletResponse response, Model model) throws UnsupportedEncodingException {// 第一步,创建一个webbook,对应一个Excel文件 HSSFWorkbook wb = new HSSFWorkbook(); HSSFFont font = wb.createFont(); // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet HSSFSheet sheet = wb.createSheet("前端订单"); /* for (int i = 0; i < 11; i++) { sheet.setColumnWidth(i, 100*60); }*/ // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short HSSFRow row = sheet.createRow((int) 0); // 第四步,创建单元格,并设置值表头 设置表头居中 HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 HSSFCell cell = row.createCell((short) 0); cell.setCellValue("订单号"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("服务月嫂"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("服务城市"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue("下单时间"); cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue("服务时间"); cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue("结束时间"); cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("订单总价"); cell.setCellStyle(style); cell = row.createCell((short)7); cell.setCellValue("订单状态"); cell.setCellStyle(style); Map<String,Object> paramMap = new HashMap<String,Object>(); // 第五步,写入实体数据 实际应用中这些数据从数据库得到, List<OrderTrade> tradeList =this.orderTradeService.selectAll(); OrderTrade ot=null; for (int i = 0; i < tradeList.size(); i++) { row = sheet.createRow((int) i + 1); ot=new OrderTrade(); ot=tradeList.get(i); // 第四步,创建单元格,并设置值 row.createCell((short) 0).setCellValue(ot.getOrderCode()); row.createCell((short) 1).setCellValue(ot.getMatronName()); row.createCell((short) 2).setCellValue(ot.getCityName()); row.createCell((short) 3).setCellValue(ot.getOrderCreateDate()); row.createCell((short) 4).setCellValue(ot.getServiceStartDate()); row.createCell((short) 5).setCellValue(ot.getActualEndDate()); row.createCell((short) 6).setCellValue(ot.getGrandTotal()); row.createCell((short) 7).setCellValue(ot.getOrderStatusName()); } // 第六步,将文件存到指定位置 try { Map<String, Object> retMap = new HashMap<String, Object>(); String resultStr = null; String filePath = request.getSession().getServletContext().getRealPath("/")+"/TradeOrder.xls"; File file=new File(filePath); //File file=new File("D:/TradeOrder.xls"); if(!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } FileOutputStream fout = new FileOutputStream(file); wb.write(fout); fout.close(); retMap.put("result", true); resultStr = JsonUtils.toJsonString(retMap); return resultStr; } catch (Exception e) { e.printStackTrace(); } return null; }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 乘性高斯噪声在深度学习网络中的应用
- ¥15 运筹学排序问题中的在线排序
- ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
- ¥30 求一段fortran代码用IVF编译运行的结果
- ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
- ¥15 C++ 头文件/宏冲突问题解决
- ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
- ¥50 安卓adb backup备份子用户应用数据失败
- ¥20 有人能用聚类分析帮我分析一下文本内容嘛
- ¥30 python代码,帮调试,帮帮忙吧