| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
| | | 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解码 |
| | | 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(); // 得到源图长
|
| | | picPX[i] = (double)widthYuan/heightYuan;
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | 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 + rownum-1);
|
| | | |
| | | HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 512, 255,(short) 0, rownum, (short) Math.ceil(10*picPX[i]), 25 + rownum-1);
|
| | | anchor.setAnchorType(3);
|
| | | patriarch.createPicture(anchor,wb.addPicture(bytes.get(i),HSSFWorkbook.PICTURE_TYPE_PNG));
|
| | | rownum+=26;
|
| | |
| | | public static double formartDouble(double b , int places){
|
| | | return new BigDecimal(b).setScale(places, BigDecimal.ROUND_HALF_UP).doubleValue();
|
| | | }
|
| | | |
| | | }
|