Pre Merge pull request !562 from jianxiong/N/A

pull/562/MERGE
jianxiong 2025-07-31 05:44:26 +00:00 committed by Gitee
commit 94c15b7825
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
*