update ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java.

扩展:获取文件流解析映射到模版类,获取实体类集合。第322 可能需要调整
//ExcelUtil<T> excelUtil = new ExcelUtil<>(t);
return ExcelUtil.importExcel(inputStream);

Signed-off-by: jianxiong <2461984449@qq.com>
pull/562/head
jianxiong 2025-07-29 11:37:45 +00:00 committed by Gitee
parent 70194aee09
commit f634d70df3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 31 additions and 0 deletions

View File

@ -300,6 +300,37 @@ public class ExcelUtil<T>
}
}
/**
*
*
* @param file Excel
* @param t
* @return
*/
public <T> List<T> analyzeExcelToList(MultipartFile file, Class<T> t) {
if (file == null || file.isEmpty()) {
log.warn("上传的文件为空");
return List.of(); // 返回空列表而非 null
}
if (t == null) {
log.error("目标实体类类型不能为空");
throw new UtilException("目标实体类类型不能为空");
}
try (InputStream inputStream = file.getInputStream()) {
ExcelUtil<T> excelUtil = new ExcelUtil<>(t);
return excelUtil.importExcel(inputStream); // 直接使用流式处理
} catch (Exception e) {
log.error("解析Excel文件到目标实体类异常", e);
throw new UtilException("解析Excel文件到目标实体类失败");
}
}
/**
* excellist
*