| | |
| | | ExportElectricityPrice(req,resp); //电价统计报表 |
| | | }else if("A059".equalsIgnoreCase(pageName)){ |
| | | ExportA059(req,resp); //A059一体机导出报表 |
| | | }else if("eleAnalyse".equalsIgnoreCase(pageName)){ |
| | | Exportele_eleAnalyseTable(req,resp); //电池组统计分析查询 |
| | | } |
| | | } |
| | | } |
| | | //电池组统计分析查询 |
| | | private void Exportele_eleAnalyseTable( HttpServletRequest req,HttpServletResponse resp |
| | | ) { |
| | | String excelTitle="电池组统计查询"; |
| | | String pictureName="电池组统计分析图"; |
| | | String[] arr_Th=req.getParameter("arr_Th").split(","); |
| | | String[] arr_Td=req.getParameter("arr_Td").split(","); |
| | | String[] echart_url=req.getParameter("echart_url").split(","); |
| | | int rowindex=4; |
| | | //System.out.println(arr_Td.length+"##"+arr_Th.length); |
| | | //定义一个工作簿 |
| | | HSSFWorkbook workbook = new HSSFWorkbook(); |
| | | HSSFSheet sheet = workbook.createSheet(excelTitle); |
| | | // 产生表格标题行 |
| | | HSSFRow title = sheet.createRow(0); |
| | | HSSFCell titlecell = title.createCell(0); |
| | | HSSFRichTextString tname = new HSSFRichTextString(excelTitle); |
| | | //System.out.print(text+"\t"); |
| | | titlecell.setCellValue(tname); |
| | | if(arr_Th!=null && arr_Th.length>0){ |
| | | HSSFRow row0 = sheet.createRow(1); |
| | | for(int i=0;i<arr_Th.length;i++){ |
| | | HSSFCell cell = row0.createCell(i); |
| | | HSSFRichTextString text = new HSSFRichTextString(arr_Th[i]); |
| | | //System.out.print(text+"\t"); |
| | | cell.setCellValue(text); |
| | | } |
| | | |
| | | if(arr_Td!=null && arr_Td.length>0){ |
| | | int rowNum=(int)(Math.ceil((double)arr_Td.length/arr_Th.length)); //总行数 |
| | | int index=0; |
| | | //System.out.println("总共有"+rowNum+"行"); |
| | | for(int i=1;i<=rowNum;i++){ |
| | | HSSFRow row = sheet.createRow(i+1); |
| | | for(int j=0;j<arr_Th.length && index<arr_Td.length;j++){ |
| | | HSSFCell cell = row.createCell(j); |
| | | HSSFRichTextString text = new HSSFRichTextString(arr_Td[index++]); |
| | | //System.out.print((i-1)*rowNum+j+"\t"); |
| | | //System.out.print(text+"\t"); |
| | | cell.setCellValue(text); |
| | | } |
| | | } |
| | | rowindex=rowNum+3; |
| | | } |
| | | } |
| | | HSSFRow row = sheet.createRow(rowindex); |
| | | HSSFCell cell = row.createCell(0); |
| | | HSSFRichTextString text = new HSSFRichTextString(pictureName); |
| | | //System.out.print((i-1)*rowNum+j+"\t"); |
| | | //System.out.print(text+"\t"); |
| | | cell.setCellValue(text); |
| | | if(echart_url!=null && echart_url.length>0){ |
| | | List<byte[]> bytes=new ArrayList<byte[]>(); |
| | | try { |
| | | bytes.add(new BASE64Decoder().decodeBuffer(echart_url[1])); |
| | | HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); |
| | | for (int i = 0; i < bytes.size(); i++) { |
| | | HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 512, 255, |
| | | (short) 0, rowindex+1, (short) 0, 1000 * (2 + 1)); |
| | | anchor.setAnchorType(3); |
| | | // 插入图片 |
| | | patriarch.createPicture( |
| | | anchor, |
| | | workbook.addPicture(bytes.get(i), |
| | | HSSFWorkbook.PICTURE_TYPE_PNG)).resize(1); |
| | | } |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | // 转码防止乱码 |
| | | try { |
| | | resp.addHeader("Content-Disposition", "attachment;filename=" |
| | | + new String(excelName.getBytes("UTF-8"), "ISO8859-1") |
| | | + ".xls"); |
| | | OutputStream out = resp.getOutputStream(); |
| | | workbook.write(out); |
| | | out.close(); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | //导出单个图表 |
| | | private void chargeExcelExprot(HttpServletRequest req, |
| | | HttpServletResponse resp) { |