From 82c1e7ced425f43781b0cd01290fad298f51e623 Mon Sep 17 00:00:00 2001 From: whyclj <1525436766@qq.com> Date: 星期六, 29 六月 2019 13:27:41 +0800 Subject: [PATCH] Merge branch 'dev_lxw' of http://whyclj@118.89.139.230:10101/r/~whyclxw/sensor.git into dev_lxw --- sensor/src/com/fgkj/servlets/EchartPictureDowloadServlet.java | 38 +++++++++++++++++++++++++++++++++----- 1 files changed, 33 insertions(+), 5 deletions(-) diff --git a/sensor/src/com/fgkj/servlets/EchartPictureDowloadServlet.java b/sensor/src/com/fgkj/servlets/EchartPictureDowloadServlet.java index bba5a7d..9f10e29 100644 --- a/sensor/src/com/fgkj/servlets/EchartPictureDowloadServlet.java +++ b/sensor/src/com/fgkj/servlets/EchartPictureDowloadServlet.java @@ -1,6 +1,9 @@ package com.fgkj.servlets; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; @@ -9,6 +12,7 @@ import java.util.Date; import java.util.List; +import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -34,6 +38,11 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String pageName = req.getParameter("pageName"); + String eName = req.getParameter("excelName"); + if(eName != null && eName.length()>0){ + excelName = eName; + } + if (ServletUtils.isNotNull(pageName)) { if ("charge-test".equalsIgnoreCase(pageName)) { chargeExcelExprot(req, resp); //瀵煎嚭鍗曚釜鍥捐〃 @@ -91,7 +100,7 @@ HttpServletResponse resp, String[][] tabData) { HSSFSheet sheet1 = wb.createSheet("琛ㄦ牸鏁版嵁"); int rownum = 0; - for(int i=0;i<tabData[0].length;i++){ + for(int i=0;i<tabData.length;i++){ sheet1.createRow(rownum); for(int j=0;j<tabData[i].length;j++){ sheet1.getRow(rownum).createCell(j+1).setCellValue(tabData[i][j]); @@ -104,12 +113,28 @@ private void ExprotReportPicData(HSSFWorkbook wb, HttpServletRequest req, HttpServletResponse resp,String[] picName,String[] picSource) { HSSFSheet sheet1 = wb.createSheet("鍥剧墖鏁版嵁"); - + double[] picPX = new double[picSource.length]; bytes = new ArrayList<byte[]>(); //灏嗗浘鐗囨暟鎹浆鎹㈡垚瀛楄妭鏁扮粍 + BASE64Decoder base64 = new BASE64Decoder(); + //Base64瑙g爜 + byte[] b; + BufferedImage src = null; for(int i = 0 ;i<picSource.length;i++ ){ try { - bytes.add(new BASE64Decoder().decodeBuffer(picSource[i].split(",")[1])); + bytes.add(base64.decodeBuffer(picSource[i].split(",")[1])); + b = base64.decodeBuffer(picSource[i].split(",")[1]); + for (int k = 0; k < b.length; ++k) { + if (b[k] < 0) {// 璋冩暣寮傚父鏁版嵁 + b[k] += 256; + } + } + InputStream buffin = new ByteArrayInputStream(b); + src = ImageIO.read(buffin); + int widthYuan = src.getWidth(); // 寰楀埌婧愬浘瀹� + int heightYuan = src.getHeight(); // 寰楀埌婧愬浘楂� + //System.out.println("width:"+widthYuan+"\theight:"+heightYuan+"\t鍗曞厓鏍煎:"+swidth+"\t鍗曞厓鏍奸珮"+sheight); + picPX[i] = (double)widthYuan/(heightYuan*4); } catch (IOException e) { e.printStackTrace(); } @@ -122,8 +147,10 @@ sheet1.createRow(rownum); sheet1.getRow(rownum).createCell(0).setCellValue(i>=picName.length?"":picName[i]); rownum++; - HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 512, 255,(short) 0, rownum, (short) 10, 25 * (i + 1)); - //anchor.setAnchorType(3); + + + HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 512, 255,(short) 0, rownum, (short) Math.ceil(25*picPX[i]), 25 + rownum-1); + anchor.setAnchorType(3); patriarch.createPicture(anchor,wb.addPicture(bytes.get(i),HSSFWorkbook.PICTURE_TYPE_PNG)); rownum+=26; } @@ -570,4 +597,5 @@ public static double formartDouble(double b , int places){ return new BigDecimal(b).setScale(places, BigDecimal.ROUND_HALF_UP).doubleValue(); } + } -- Gitblit v1.9.1