yinzuomei 3 years ago
parent
commit
c2d7289a42
  1. 22
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ExcelPoiUtils.java
  2. 2
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java

22
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ExcelPoiUtils.java

@ -7,6 +7,7 @@ import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.afterturn.easypoi.excel.imports.ExcelImportService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.multipart.MultipartFile;
@ -228,6 +229,27 @@ public class ExcelPoiUtils {
throw new IOException(e.getMessage());
}
}
public static <T> ExcelImportResult<T> importExcel1(InputStream inputStream, Integer titleRows, Integer headerRows, Class<T> pojoClass) throws IOException {
if (inputStream == null) {
return null;
}
ImportParams params = new ImportParams();
params.setTitleRows(titleRows);
params.setHeadRows(headerRows);
params.setSaveUrl("/tmp/excel/");
params.setNeedSave(false);
try {
// return ExcelImportUtil.importExcel(inputStream, pojoClass, params);
return (new ExcelImportService()).importExcelByIs(inputStream, pojoClass, params, false);
} catch (NoSuchElementException e) {
throw new IOException("excel文件不能为空");
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
/**
* excel 导入有错误信息
*

2
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java

@ -510,7 +510,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
List<CommunitySelfOrgImportExcel> fileList = new ArrayList<>();
CommunitySelfOrgImportExcel excel = null;
//1.读取Excel数据
ExcelImportResult<ImportCommunitySelfOrganization> testExcelImportResult = ExcelPoiUtils.importExcelMore(inputStream,0,2,ImportCommunitySelfOrganization.class);
ExcelImportResult<ImportCommunitySelfOrganization> testExcelImportResult = ExcelPoiUtils.importExcel1(inputStream,0,2,ImportCommunitySelfOrganization.class);
//2.存在错误行数据时存入错误数据集合中
for (ImportCommunitySelfOrganization entity : testExcelImportResult.getFailList()) {
//打印失败的行 和失败的信息

Loading…
Cancel
Save