Commit e87f4bc6cb7a711fcdfebae555b0f976bb433a93

Authored by YunaiV
1 parent aa72a944

fix: 增加 try 处理以兼容 Windows 场景的 Excel 文件读取

yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/util/ExcelUtils.java
@@ -9,6 +9,7 @@ import jakarta.servlet.http.HttpServletResponse; @@ -9,6 +9,7 @@ import jakarta.servlet.http.HttpServletResponse;
9 import org.springframework.web.multipart.MultipartFile; 9 import org.springframework.web.multipart.MultipartFile;
10 10
11 import java.io.IOException; 11 import java.io.IOException;
  12 +import java.io.InputStream;
12 import java.util.List; 13 import java.util.List;
13 14
14 /** 15 /**
@@ -44,9 +45,12 @@ public class ExcelUtils { @@ -44,9 +45,12 @@ public class ExcelUtils {
44 } 45 }
45 46
46 public static <T> List<T> read(MultipartFile file, Class<T> head) throws IOException { 47 public static <T> List<T> read(MultipartFile file, Class<T> head) throws IOException {
47 - return FastExcelFactory.read(file.getInputStream(), head, null)  
48 - .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理  
49 - .doReadAllSync(); 48 + // 参考 https://t.zsxq.com/zM77F 帖子,增加 try 处理,兼容 windows 场景
  49 + try (InputStream inputStream = file.getInputStream()) {
  50 + return FastExcelFactory.read(inputStream, head, null)
  51 + .autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理
  52 + .doReadAllSync();
  53 + }
50 } 54 }
51 55
52 } 56 }