From 9aa63389a2124c76fd28fa6ee3271bf5b5eb3bf1 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期四, 20 三月 2025 08:53:03 +0800 Subject: [PATCH] 测试运行支持string类型 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/Readtxt.java | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 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 8bbb43a..6efe3b1 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 @@ -1,8 +1,8 @@ package com.iailab.module.model.mpk.common.utils; +import com.iailab.module.model.common.utils.ASCIIUtil; import org.apache.poi.ss.usermodel.*; -import org.apache.poi.ss.util.CellRangeAddress; import org.springframework.web.multipart.MultipartFile; import java.io.*; @@ -132,14 +132,26 @@ for (int k = 0; k < cells; k++) { //获取每一个单元格的数据 Cell cell = row.getCell(k, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); - doubles1[k] = cell.getNumericCellValue(); + CellType cellType = cell.getCellType(); + if (cellType.equals(CellType.NUMERIC)) { + doubles1[k] = cell.getNumericCellValue(); + } else if (cellType.equals(CellType.STRING)) { + // 校验数据格式 + if (k != 0) { + throw new RuntimeException(); + } + String stringCellValue = cell.getStringCellValue(); + doubles1 = ASCIIUtil.stringToAsciiArray(stringCellValue); + break; + } + } doubles2[j] = doubles1; } datas.add(doubles2); } } catch (Exception e) { - throw new RuntimeException("解析Excel异常",e); + throw new RuntimeException("解析Excel异常", e); } return datas; -- Gitblit v1.9.3