From 912a1e5f0b4537902b97ff81594611a8b6b3a853 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期一, 30 九月 2024 17:33:31 +0800 Subject: [PATCH] 动态加载、卸载 jar、dll 模型测试运行 替换临时文件夹 --- 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