EXCEL 后台导出
来源:互联网 发布:暮光女 出柜 知乎 编辑:程序博客网 时间:2024/05/17 15:41
request.setAttribute("ContentType", "text/xml;charset=utf-8"); String parklotsName = request.getParameter("parklotsName"); parklotsName=new String(parklotsName.getBytes("iso8859-1"),"UTF-8"); String inTime = request.getParameter("inTime"); String toTime=request.getParameter("toTime"); String payType = request.getParameter("payType"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Long time = 0L; Long endToTime=0L; //截止时间 try { if(!"".equals(inTime)) { time=sdf.parse(inTime).getTime();//86400000 } if(!"".equals(toTime)){ endToTime=sdf.parse(toTime).getTime()+86400000; }else{ endToTime = time+86400000; } } catch (ParseException e1) { e1.printStackTrace(); } pdaOrderMng service = new pdaOrderMng(); List<PdaOrder> orderList = new ArrayList<PdaOrder>(); orderList=service.queryPdaOrder(parklotsName,time,endToTime,payType); GetAppUserMng mng = new GetAppUserMng(); HSSFWorkbook wb = new HSSFWorkbook(); // 2.在workbook中添加一个sheet,对应Excel中的一个sheet HSSFSheet sheet = wb.createSheet("交易明细"); // 3.在sheet中添加表头第0行,老版本poi对excel行数列数有限制short HSSFRow row = sheet.createRow((int) 0); // 4.创建单元格,设置值表头,设置表头居中 HSSFCellStyle style = wb.createCellStyle(); // 居中格式 style.setAlignment(HSSFCellStyle.ALIGN_CENTER); row.setRowStyle(style); // 设置表头 HSSFCell cell = row.createCell(0); cell.setCellValue("#"); cell.setCellStyle(style); cell = row.createCell(1); cell.setCellValue("订单编号"); cell.setCellStyle(style); cell = row.createCell(2); cell.setCellValue("停车场名称"); cell.setCellStyle(style); cell = row.createCell(3); cell.setCellValue("泊位编号"); cell.setCellStyle(style); cell = row.createCell(4); cell.setCellValue("车牌号"); cell.setCellStyle(style); cell = row.createCell(5); cell.setCellValue("进入时间"); cell.setCellStyle(style); cell = row.createCell(6); cell.setCellValue("离开时间"); cell.setCellStyle(style); cell = row.createCell(7); cell.setCellValue("支付方式"); cell.setCellStyle(style); cell = row.createCell(8); cell.setCellValue("应收金额"); cell.setCellStyle(style); cell = row.createCell(9); cell.setCellValue("实收金额"); cell.setCellStyle(style); cell = row.createCell(10); cell.setCellValue("员工编号"); cell.setCellStyle(style); int i=0; for(PdaOrder bean:orderList){ row = sheet.createRow((int) i + 1); row.createCell(0).setCellValue(++i); row.createCell(1).setCellValue(bean.getOrderNo()); row.createCell(2).setCellValue(bean.getParklots()); row.createCell(3).setCellValue(bean.getBoWei()); row.createCell(4).setCellValue(bean.getCarNo()); row.createCell(5).setCellValue(bean.getStartTime()); row.createCell(6).setCellValue(bean.getEndTime()); if(bean.getTrade_way()==null){ row.createCell(7).setCellValue( ""); }else if(bean.getTrade_way().equals("0")){ row.createCell(7).setCellValue("支付宝"); }else if(bean.getTrade_way().equals("2")){ row.createCell(7).setCellValue( "微信"); }else if(bean.getTrade_way().equals("3")){ row.createCell(7).setCellValue("现金缴费"); }else if(bean.getTrade_way().equals("4")){ row.createCell(7).setCellValue("琴岛通卡"); }else if(bean.getTrade_way().equals("5")){ row.createCell(7).setCellValue( "逃单"); }else if(bean.getTrade_way().equals("6")){ row.createCell(7).setCellValue("免费停车"); }else if(bean.getTrade_way().equals("7")){ row.createCell(7).setCellValue( "微信APP"); } row.createCell(8).setCellValue(bean.getMoney()); row.createCell(9).setCellValue(bean.getMoney()); row.createCell(10).setCellValue(bean.getUserNO()); } Date date = new Date(); SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式 String fileName = "交易明细"+sf.format(date); ByteArrayOutputStream os = new ByteArrayOutputStream(); wb.write(os); byte[] content = os.toByteArray(); InputStream is = new ByteArrayInputStream(content); // 设置response参数,可以打开下载页面 response.reset(); response.setContentType("application/vnd.ms-excel;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1")); ServletOutputStream out = response.getOutputStream(); BufferedInputStream bis = null; BufferedOutputStream bos = null; try { bis = new BufferedInputStream(is); bos = new BufferedOutputStream(out); byte[] buff = new byte[2048]; int bytesRead; // Simple read/write loop. while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff, 0, bytesRead); } } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { if (bis != null) bis.close(); if (bos != null) bos.close(); }
阅读全文
0 0
- .NET后台导出EXCEL
- JSP 后台导出Excel
- EXCEL 后台导出
- java后台导出excel
- Extjs4---后台导出excel poi
- 页面请求后台,导出Excel
- Java后台list导出excel
- net后台导出到excel word
- 展现报表同时后台导出excel
- java导出Excel之前台后台
- 前台EXTJS后台JAVA导出EXCEL
- 后台运用html格式导出Excel文件
- Python aiohttp后台导出excel文件
- java Excel导出 后台下载出来
- java后台导出excel,客户端下载
- poi导出excel后台代码示例
- 后台导出GridView到Excel,可选择要导出的列
- java后台poi方式导出excel和解析excel
- Glide之加载图片
- 《android 手机网络连接情况工具类》
- Windows 搭建swagger editor 和swagger ui
- java.io.IOException: read failed: EBADF (Bad file descriptor)
- 日期和时间工具
- EXCEL 后台导出
- 牛腩新闻发布系统--分页学习(AspnetPager控件)
- Pandas中,一组数据中,分离出已有数据和新数据
- shell中颜色的设置(不错的总结,别人的)
- HDU 1506 Largest Rectangle in a Histogram (单调栈)
- [LeetCode] String to Integer (atoi)
- 华为云桌面每台服务器应发布虚拟机台数计算
- 在C语言中什么是定义?什么是声明?它们有何区别?
- HDU-1024-Max Sum Plus Plus