Excel导入增加支持多行表头表格导入

pull/34/head
yxx 2022-08-11 10:39:33 +08:00
parent 23f79b541e
commit 0bc68d87a6
2 changed files with 36 additions and 1 deletions

View File

@ -61,10 +61,21 @@ public interface OfficeExcelApi {
* @param inputStream Excel
* @param clazz
* @return List
*
* @author luojie
* @date 2020/11/4 13:54
*/
<T> List<T> easyReadToList(InputStream inputStream, Class<T> clazz);
/**
* ExcelList-
*
* @param inputStream Excel
* @param clazz
* @param rowNum
* @return List
* @author yxx
* @date 2022/8/11 10:37
*/
<T> List<T> easyReadToList(InputStream inputStream, Integer rowNum, Class<T> clazz);
}

View File

@ -77,6 +77,30 @@ public class OfficeExcel implements OfficeExcelApi {
return readListener.getDataList();
}
@Override
public <T> List<T> easyReadToList(InputStream inputStream, Integer rowNum, Class<T> clazz) {
if (inputStream == null) {
return new ArrayList<T>();
}
// 创建一个简单的数据监听器
SimpleDataListener<T> readListener = new SimpleDataListener<T>();
// 读取文件
try {
EasyExcel.read(inputStream, clazz, readListener).sheet().headRowNumber(rowNum).doRead();
} catch (Exception e) {
log.error(e.getMessage());
// 组装提示信息
String userTip = OfficeExceptionEnum.OFFICE_ERROR.getUserTip();
String finalUserTip = StrUtil.format(userTip, e.getMessage());
throw new OfficeException(OfficeExceptionEnum.OFFICE_ERROR.getErrorCode(), finalUserTip);
}
return readListener.getDataList();
}
@Override
public void easyWriteToFile(ExcelExportParam excelExportParam) {