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

This commit is contained in:
YunaiV
2025-11-22 09:08:03 +08:00
parent aa72a94428
commit e87f4bc6cb

View File

@@ -9,6 +9,7 @@ import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
/** /**
@@ -44,9 +45,12 @@ public class ExcelUtils {
} }
public static <T> List<T> read(MultipartFile file, Class<T> head) throws IOException { public static <T> List<T> read(MultipartFile file, Class<T> head) throws IOException {
return FastExcelFactory.read(file.getInputStream(), head, null) // 参考 https://t.zsxq.com/zM77F 帖子,增加 try 处理,兼容 windows 场景
.autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理 try (InputStream inputStream = file.getInputStream()) {
.doReadAllSync(); return FastExcelFactory.read(inputStream, head, null)
.autoCloseStream(false) // 不要自动关闭,交给 Servlet 自己处理
.doReadAllSync();
}
} }
} }