mirror of
https://gitee.com/yudaocode/yudao-boot-mini.git
synced 2026-03-22 05:27:15 +08:00
fix: 增加 try 处理以兼容 Windows 场景的 Excel 文件读取
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user