From 047808a2d34b40cc9ad2be83e5141bcc3a07d91f Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期一, 16 六月 2025 10:39:47 +0800
Subject: [PATCH] 提交
---
server/system_service/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java | 43 +++++++++++++++++++++++++++++++++++++++++--
1 files changed, 41 insertions(+), 2 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 8f98162..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){
@@ -295,7 +333,8 @@
}else{
val = String.valueOf(val.toString()).trim();
}
- }else if (valType == Integer.class){
+ }
+ else if (valType == Integer.class){
val = Double.valueOf(val.toString()).intValue();
}else if (valType == Long.class){
val = Double.valueOf(val.toString()).longValue();
--
Gitblit v1.9.3