From c0c92ddfa2a626d2794f4b5e184cf9deed4086f3 Mon Sep 17 00:00:00 2001 From: 林致杰 <1003392067@qq.com> Date: 星期二, 02 八月 2022 10:52:47 +0800 Subject: [PATCH] 优化 --- src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java b/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java index 0dd7306..fdc8777 100644 --- a/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java +++ b/src/main/java/com/ots/project/tool/report/MAQTR/chart/MAQTRChart.java @@ -34,9 +34,9 @@ public static void main(String[] args) throws IOException { try { OutputStream os = new FileOutputStream("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\鏋梍PAQ_IA_CN2.docx"); - XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\缁堢銆�0607涓枃鐗堛�慚AQ缁勫埆瀵规瘮鎶ュ憡.docx")); + XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\缁堢銆�0607涓枃鐗堛�慚AQ缁勫埆瀵规瘮鎶ュ憡(1).docx")); - String fileName = "C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\缁勫埆瀵规瘮鎶ュ憡娴嬭瘯鏁版嵁.xlsx"; + String fileName = "C:\\Users\\澶уご\\Desktop\\MAQ缁勫埆鎶ュ憡\\MAQ缁勫埆瀵煎叆鏁版嵁妯℃澘 (2).xlsx"; //鍙樻洿鍥捐〃鏁版嵁 changeMAQTRChart(document,fileName); document.write(os); @@ -65,9 +65,15 @@ //琛� for (int j = 1; j <= sheet.getLastRowNum(); j++) { XSSFRow row = sheet.getRow(j); + if(row == null){ + continue; + } //鍒� for (int k = 1; k < row.getLastCellNum(); k++) { XSSFCell cell = row.getCell(k); + if(cell == null){ + continue; + } /* if (CellType.NUMERIC == cell.getCellType()) { System.out.println(cell.getNumericCellValue()); @@ -75,6 +81,10 @@ System.out.println(cell.getStringCellValue()); } */ + switch (cell.getCellType()) { + case STRING: + continue; + } //table1 澶氫釜绛旈缁撴灉澶勭悊 if(map.get(k) != null){ map.get(k).add(cell.getNumericCellValue()); @@ -495,9 +505,12 @@ } //鍒犻櫎澶氫綑琛屾暟 int lastRowNum = sheet.getLastRowNum(); - //log.error("lastRowNum:{},size:{}",lastRowNum,size); + log.error("lastRowNum:{},size:{}",lastRowNum,size); if (lastRowNum > size) { for (int idx = lastRowNum; idx > size; idx--) { + if(sheet.getRow(idx) == null){ + continue; + } sheet.removeRow(sheet.getRow(idx)); } } -- Gitblit v1.9.1