excelpoi
cn.afterturn.easypoi.excel包下有这样一段代码
public static <T> List<T> importExcel(InputStream inputstream, Class<?> pojoClass, ImportParams params) throws Exception {
return (new ExcelImportService()).importExcelByIs(inputstream, pojoClass, params, false).getList();
}
我们需要对导入文件进行做一些自定义规则判断于是封装了一段代码
private <T> List<T> getImportExcel(MultipartFile file, Class<?> pojoClass) {
List<T> importExcel;
try {
ImportParams importParams = new ImportParams();
importParams.setVerifyHandler(classExcelVerifyHandler);
importExcel = ExcelImportUtil.importExcel(file.getInputStream(),pojoClass, importParams);
} catch (Exception e) {
log.error(e.toString());
throw new RuntimeException("文件读取失败!");
}
return importExcel;