From 79914dabac38d83676ea16ff65da8d941a099285 Mon Sep 17 00:00:00 2001
From: Jay <csj123456>
Date: 星期二, 08 十月 2024 10:38:01 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/Readtxt.java |   52 ++++++++++++++++++++++++++++------------------------
 1 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/Readtxt.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/Readtxt.java
index fd3e96e..8bbb43a 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/Readtxt.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/Readtxt.java
@@ -110,32 +110,36 @@
     }
 
     public static List<double[][]> readMethodExcel(MultipartFile file) throws IOException {
-        Workbook workbook = WorkbookFactory.create(file.getInputStream());
-        //获取工作薄里面sheet的个数
-        int sheetNum = workbook.getNumberOfSheets();
-        List<double[][]> datas = new ArrayList<>(sheetNum - 1);
-        //从第二个sheet开始读,第一个为示例
-        for (int i = 1; i < sheetNum; i++) {
-            Sheet sheet = workbook.getSheetAt(i);
-            //获取sheet中有数据的行数
-            int rows = sheet.getPhysicalNumberOfRows();
-            double[][] doubles2 = new double[rows][];
-            for (int j = 0; j < rows; j++) {
-                //获取每一行的数据
-                Row row = sheet.getRow(j);
-                //得到每一行中有效单元格的数据
-                short cells = row.getLastCellNum();
-                //定义一个doubles数组用来存储读取单元格的数据
-                double[] doubles1 = new double[cells];
-                //遍历每一个有效的单元格数据
-                for (int k = 0; k < cells; k++) {
-                    //获取每一个单元格的数据
-                    Cell cell = row.getCell(k, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
-                    doubles1[k] = cell.getNumericCellValue();
+        List<double[][]> datas;
+        try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
+            //获取工作薄里面sheet的个数
+            int sheetNum = workbook.getNumberOfSheets();
+            datas = new ArrayList<>(sheetNum - 1);
+            //从第二个sheet开始读,第一个为示例
+            for (int i = 1; i < sheetNum; i++) {
+                Sheet sheet = workbook.getSheetAt(i);
+                //获取sheet中有数据的行数
+                int rows = sheet.getPhysicalNumberOfRows();
+                double[][] doubles2 = new double[rows][];
+                for (int j = 0; j < rows; j++) {
+                    //获取每一行的数据
+                    Row row = sheet.getRow(j);
+                    //得到每一行中有效单元格的数据
+                    short cells = row.getLastCellNum();
+                    //定义一个doubles数组用来存储读取单元格的数据
+                    double[] doubles1 = new double[cells];
+                    //遍历每一个有效的单元格数据
+                    for (int k = 0; k < cells; k++) {
+                        //获取每一个单元格的数据
+                        Cell cell = row.getCell(k, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
+                        doubles1[k] = cell.getNumericCellValue();
+                    }
+                    doubles2[j] = doubles1;
                 }
-                doubles2[j] = doubles1;
+                datas.add(doubles2);
             }
-            datas.add(doubles2);
+        } catch (Exception e) {
+            throw new RuntimeException("解析Excel异常",e);
         }
 
         return datas;

--
Gitblit v1.9.3