|
@@ -7,6 +7,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
|
|
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
|
|
+import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
|
|
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
@@ -183,4 +184,29 @@ public class ExcelUtils {
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public static <T> ExcelImportResult<T> importExcelMore(MultipartFile file, Integer titleRows, Integer headerRows,
|
|
|
+ Class<T> pojoClass) {
|
|
|
+ if (file == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setTitleRows(titleRows);
|
|
|
+ params.setHeadRows(headerRows);
|
|
|
+ ExcelImportResult<T> result = null;
|
|
|
+ try {
|
|
|
+ result = ExcelImportUtil.importExcelMore(file.getInputStream(), pojoClass, params);
|
|
|
+ } catch (NoSuchElementException e) {
|
|
|
+ // throw new NormalException("excel文件不能为空");
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "excel文件不能为空");
|
|
|
+ } catch (ExcelImportException e) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "校验失败,请使用模板进行数据导入");
|
|
|
+ } catch (Exception e) {
|
|
|
+ // throw new NormalException(e.getMessage());
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "导入Excel异常");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|