mirror of https://gitee.com/stylefeng/roses
Excel导入增加支持多行表头表格导入
parent
23f79b541e
commit
0bc68d87a6
|
@ -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);
|
||||
|
||||
/**
|
||||
* 简单的读取Excel文件并返回实体类List集合-针对多行表头
|
||||
*
|
||||
* @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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue