From 88f72df1efba56e731aac80de4d9f3b879cc85cf Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期四, 29 一月 2026 14:29:17 +0800
Subject: [PATCH] 提交忽略文件

---
 server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java b/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
index a1d7252..56eb9a9 100644
--- a/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
+++ b/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
@@ -10,10 +10,7 @@
 import org.slf4j.LoggerFactory;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.*;
@@ -147,12 +144,13 @@
     }
     public ExcelImporter(String fileName, InputStream in, int headerNum, int sheetIndex,CellType cellType)
         throws InvalidFormatException, IOException {
+        ByteArrayOutputStream buffer = toByteArray(in);
         if (StringUtils.isBlank(fileName)){
             throw new RuntimeException("瀵煎叆鏂囨。涓虹┖!");
         }else if(fileName.toLowerCase().endsWith("xls")){
-            this.wb = new HSSFWorkbook(in);
+            this.wb = new HSSFWorkbook(new ByteArrayInputStream(buffer.toByteArray()));
         }else if(fileName.toLowerCase().endsWith("xlsx")){
-            this.wb = new XSSFWorkbook(in);
+            this.wb = new XSSFWorkbook(new ByteArrayInputStream(buffer.toByteArray()));
         }else{
             throw new RuntimeException("鏂囨。鏍煎紡涓嶆纭�!");
         }
@@ -162,10 +160,27 @@
         this.sheet = this.wb.getSheetAt(sheetIndex);
         this.headerNum = headerNum;
         this.changeType = cellType;
-        this.pictureList = ExcelPictureUtil.getExcelPictures(in);
+        this.pictureList = ExcelPictureUtil.getExcelPictures(new ByteArrayInputStream(buffer.toByteArray()));
         log.debug("Initialize success.");
     }
 
+    public static ByteArrayOutputStream toByteArray(InputStream inputStream) {
+        try {
+            // 缂撳瓨鏂囦欢娴�
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+            byte[] data = new byte[1024];
+            int nRead;
+            while ((nRead = inputStream.read(data, 0, data.length))!= -1) {
+                buffer.write(data, 0, nRead);
+            }
+            buffer.flush();
+
+           return  buffer;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 
 
     /**
@@ -357,6 +372,7 @@
                                     "fieldtype."+valType.getSimpleName()+"Type")).getMethod("getValue", String.class).invoke(null, val.toString());
                             }
                         }
+
                     } catch (Exception ex) {
                         log.info("Get cell value ["+i+","+column+"] error: " + ex.toString());
                         val = null;

--
Gitblit v1.9.3