From 2900f282fdcd6331065721a7f5f637c190198b61 Mon Sep 17 00:00:00 2001 From: zhangsan Date: Sat, 30 Apr 2022 01:23:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7hutool=E3=80=81poi=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 ++++++------ util/src/main/java/com/ccsens/util/PoiUtil.java | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index f8d92cf..4d4456b 100644 --- a/pom.xml +++ b/pom.xml @@ -116,15 +116,15 @@ - - org.apache.poi - poi - 3.17 - + + + + + org.apache.poi poi-ooxml - 3.17 + 4.1.2 diff --git a/util/src/main/java/com/ccsens/util/PoiUtil.java b/util/src/main/java/com/ccsens/util/PoiUtil.java index bffd1d0..a75e829 100644 --- a/util/src/main/java/com/ccsens/util/PoiUtil.java +++ b/util/src/main/java/com/ccsens/util/PoiUtil.java @@ -5,9 +5,9 @@ import cn.hutool.core.util.StrUtil; import com.ccsens.util.exception.BaseException; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; @@ -350,7 +350,7 @@ public class PoiUtil { String cellValue = null; // 判断excel单元格内容的格式,并对其进行转换,以便插入数据库 switch (cell.getCellType()) { - case 0://number类型 + case NUMERIC://number类型 //时间类型也被认为是number类型,所以在读取数据时需进行判断 if (DateUtil.isCellDateFormatted(cell)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); @@ -359,10 +359,10 @@ public class PoiUtil { cellValue = new DecimalFormat("0").format(cell.getNumericCellValue()); } break; - case 1: + case STRING: cellValue = cell.getStringCellValue(); break; - case 2: + case FORMULA: if (DateUtil.isCellDateFormatted(cell)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); cellValue = sdf.format(cell.getDateCellValue()); @@ -370,13 +370,13 @@ public class PoiUtil { cellValue = String.valueOf(cell.getNumericCellValue()); } break; - case 3: + case BLANK: cellValue = ""; break; - case 4: + case BOOLEAN: cellValue = String.valueOf(cell.getBooleanCellValue()); break; - case 5: + case ERROR: cellValue = String.valueOf(cell.getErrorCellValue()); break; } @@ -513,7 +513,7 @@ public class PoiUtil { InputStream inputStream = new FileInputStream(file); Workbook workbook; if (file.getPath().endsWith(".xls")) { - workbook = new XSSFWorkbook(inputStream); + workbook = new HSSFWorkbook(inputStream); } else { workbook = new XSSFWorkbook(inputStream); }