From 6f1203d1cf895efc473fade3ab049fc30d92c618 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期三, 26 三月 2025 16:48:23 +0800
Subject: [PATCH] 优化
---
server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java | 40 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java b/server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
index d3c494c..f8f067c 100644
--- a/server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
+++ b/server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
@@ -38,6 +38,10 @@
* 鏍囬琛屽彿
*/
private int headerNum;
+ /**
+ * 鏍囬琛屽彿
+ */
+ private CellType changeType;
/**
* 鏋勯�犲嚱鏁�
@@ -101,6 +105,18 @@
throws InvalidFormatException, IOException {
this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetIndex);
}
+ /**
+ * 鏋勯�犲嚱鏁� (閲嶈)
+ * @param--file 瀵煎叆鏂囦欢瀵硅薄
+ * @param headerNum 鏍囬琛屽彿锛屾暟鎹鍙�=鏍囬琛屽彿+1
+ * @param sheetIndex 宸ヤ綔琛ㄧ紪鍙�
+ * @throws InvalidFormatException
+ * @throws IOException
+ */
+ public ExcelImporter(MultipartFile multipartFile, int headerNum, int sheetIndex, CellType cellType)
+ throws InvalidFormatException, IOException {
+ this(multipartFile.getOriginalFilename(), multipartFile.getInputStream(), headerNum, sheetIndex,cellType);
+ }
/**
* 鏋勯�犲嚱鏁� 锛堬級
@@ -128,6 +144,27 @@
this.headerNum = headerNum;
log.debug("Initialize success.");
}
+ public ExcelImporter(String fileName, InputStream in, int headerNum, int sheetIndex,CellType cellType)
+ throws InvalidFormatException, IOException {
+ if (StringUtils.isBlank(fileName)){
+ throw new RuntimeException("瀵煎叆鏂囨。涓虹┖!");
+ }else if(fileName.toLowerCase().endsWith("xls")){
+ this.wb = new HSSFWorkbook(in);
+ }else if(fileName.toLowerCase().endsWith("xlsx")){
+ this.wb = new XSSFWorkbook(in);
+ }else{
+ throw new RuntimeException("鏂囨。鏍煎紡涓嶆纭�!");
+ }
+ if (this.wb.getNumberOfSheets()<sheetIndex){
+ throw new RuntimeException("鏂囨。涓病鏈夊伐浣滆〃!");
+ }
+ this.sheet = this.wb.getSheetAt(sheetIndex);
+ this.headerNum = headerNum;
+ this.changeType = cellType;
+ log.debug("Initialize success.");
+ }
+
+
/**
* 鑾峰彇琛屽璞�
@@ -174,7 +211,8 @@
Cell cell = row.getCell(column);
if (cell != null){
if (cell.getCellType() == CellType.NUMERIC){
- val = cell.getNumericCellValue();
+ cell.setCellType(CellType.STRING); // 纭繚鍗曞厓鏍肩被鍨嬩负瀛楃涓�
+ val = cell.getStringCellValue();
}else if (cell.getCellType() == CellType.STRING){
val = cell.getStringCellValue();
}else if (cell.getCellType() == CellType.FORMULA){
--
Gitblit v1.9.3