| | |
| | | import com.whyc.fbo.FboDataHeadStart; |
| | | import com.whyc.fbo.FboDataHeadStop; |
| | | import com.whyc.fbo.FboDataInf; |
| | | import com.whyc.res.RESData; |
| | | import com.whyc.res.RESDataInfo; |
| | | import com.whyc.util.ServletUtils; |
| | | import org.apache.poi.ss.usermodel.ClientAnchor; |
| | | import org.apache.poi.xssf.usermodel.*; |
| | |
| | | public class ExcelExportService { |
| | | @Autowired |
| | | FboDataInfService fboService; |
| | | |
| | | @Autowired |
| | | private RESDataInfoService resService; |
| | | |
| | | //导出fbx |
| | | public void exportFbx(HttpServletRequest req, HttpServletResponse resp){ |
| | |
| | | } |
| | | |
| | | |
| | | //导出bres |
| | | public void exportBres(HttpServletRequest req, HttpServletResponse resp){ |
| | | String volEchart = req.getParameter("vol_echart"); //单体电压折线图 |
| | | String resEchart = req.getParameter("res_echart"); //单体内阻折线图 |
| | | String tmpEchart = req.getParameter("tmp_echart"); //单体温度折线图 |
| | | |
| | | String filePath = req.getParameter("filePath"); |
| | | //图片base64后的数据 |
| | | List<byte[]> bytes = new ArrayList<>(); |
| | | try { |
| | | if (ServletUtils.isNotNull(volEchart)) { |
| | | String[] url = volEchart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | if (ServletUtils.isNotNull(resEchart)) { |
| | | String[] url = resEchart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | if (ServletUtils.isNotNull(tmpEchart)) { |
| | | String[] url = tmpEchart.split(","); |
| | | bytes.add(new BASE64Decoder().decodeBuffer(url[1])); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | //当前日期 |
| | | String nowFormat = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | String excelName = "BRES-"+nowFormat; |
| | | XSSFWorkbook wb = new XSSFWorkbook(); |
| | | XSSFSheet sheet = wb.createSheet("数据总表"); |
| | | //图片元素 |
| | | XSSFDrawing patriarch = sheet.createDrawingPatriarch(); |
| | | |
| | | int rowNumSheet = 0; |
| | | //插入图片 |
| | | int picNum = 0; |
| | | String[] picName =new String[]{"单体电压折线图","单体内阻折线图","单体温度折线图"}; |
| | | if (picName.length==bytes.size()){ |
| | | for(int i=0;i<picName.length;i++){ |
| | | sheet.createRow(rowNumSheet-1); |
| | | sheet.getRow(rowNumSheet-1).createCell(0).setCellValue(picName[i]); |
| | | //rowNum++; |
| | | XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 512, 255,(short) 0, rowNumSheet, (short) 10, rowNumSheet+27); |
| | | anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE); |
| | | patriarch.createPicture(anchor,wb.addPicture(bytes.get(picNum),XSSFWorkbook.PICTURE_TYPE_PNG)).resize(1); |
| | | picNum ++; |
| | | rowNumSheet+=27; |
| | | } |
| | | } |
| | | //数据 |
| | | RESDataInfo resDataInfo =resService.readFileData(filePath); |
| | | //从文件中获取数据 |
| | | List<RESData> list = resDataInfo.resDatas; |
| | | XSSFSheet sheet1 = wb.createSheet("内阻数据"); |
| | | //新建行 |
| | | |
| | | //抬头 |
| | | int rowNum = 0; |
| | | sheet1.createRow(rowNum).createCell(0).setCellValue("测试数据(内阻)"); |
| | | rowNum++; |
| | | //属性栏 |
| | | String[] rowName =new String[]{"测试时间"}; |
| | | XSSFRow row = sheet1.createRow(rowNum); |
| | | for (int i=0;i<rowName.length;i++){ |
| | | row.createCell(i).setCellValue(rowName[i]); |
| | | } |
| | | int battNum=list.get(0).getBattSum();//单体个数 |
| | | for(int i=0;i<battNum;i++){ |
| | | row.createCell(rowName.length+i).setCellValue("#"+Integer.valueOf(i+1)); |
| | | } |
| | | rowNum++; |
| | | //数据栏 |
| | | for (int i = 0; i < list.size(); i++) { |
| | | sheet1.createRow(rowNum); //创建行 |
| | | RESData resData=list.get(i); |
| | | float[] monomerRes=resData.getMonomerRes(); |
| | | sheet1.getRow(rowNum).createCell(0).setCellValue(resData.getData_Time()); |
| | | for (int k = 0;k<battNum;k++){ |
| | | sheet1.getRow(rowNum).createCell(k+1).setCellValue(monomerRes[i]); |
| | | } |
| | | rowNum++; |
| | | } |
| | | |
| | | rowNum++; |
| | | |
| | | try { |
| | | // 转码防止乱码 |
| | | resp.addHeader("Content-Disposition", "attachment;filename=" |
| | | + new String(excelName.getBytes("UTF-8"), "ISO8859-1") |
| | | + ".xlsx"); |
| | | OutputStream out = resp.getOutputStream(); |
| | | wb.write(out); |
| | | out.close(); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 将日期格式转换成指定的字符串格式 |
| | | * @param date 日期 |