org.jeecgframework.poi.excel.ExcelImportUtil Java Examples

The following examples show how to use org.jeecgframework.poi.excel.ExcelImportUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SysRoleServiceImpl.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public Result importExcelCheckRoleCode(MultipartFile file, ImportParams params) throws Exception {
    List<Object> listSysRoles = ExcelImportUtil.importExcel(file.getInputStream(), SysRole.class, params);
    int totalCount = listSysRoles.size();
    List<String> errorStrs = new ArrayList<>();

    // 去除 listSysRoles 中重复的数据
    for (int i = 0; i < listSysRoles.size(); i++) {
        String roleCodeI =((SysRole)listSysRoles.get(i)).getRoleCode();
        for (int j = i + 1; j < listSysRoles.size(); j++) {
            String roleCodeJ =((SysRole)listSysRoles.get(j)).getRoleCode();
            // 发现重复数据
            if (roleCodeI.equals(roleCodeJ)) {
                errorStrs.add("第 " + (j + 1) + " 行的 roleCode 值:" + roleCodeI + " 已存在,忽略导入");
                listSysRoles.remove(j);
                break;
            }
        }
    }
    // 去掉 sql 中的重复数据
    Integer errorLines=0;
    Integer successLines=0;
    List<String> list = ImportExcelUtil.importDateSave(listSysRoles, ISysRoleService.class, errorStrs, CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE);
     errorLines+=list.size();
     successLines+=(listSysRoles.size()-errorLines);
    return ImportExcelUtil.imporReturnRes(errorLines,successLines,list);
}
 
Example #2
Source File: SysRoleServiceImpl.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Result importExcelCheckRoleCode(MultipartFile file, ImportParams params) throws Exception {
    List<Object> listSysRoles = ExcelImportUtil.importExcel(file.getInputStream(), SysRole.class, params);
    int totalCount = listSysRoles.size();
    List<String> errorStrs = new ArrayList<>();

    // 去除 listSysRoles 中重复的数据
    for (int i = 0; i < listSysRoles.size(); i++) {
        String roleCodeI =((SysRole)listSysRoles.get(i)).getRoleCode();
        for (int j = i + 1; j < listSysRoles.size(); j++) {
            String roleCodeJ =((SysRole)listSysRoles.get(j)).getRoleCode();
            // 发现重复数据
            if (roleCodeI.equals(roleCodeJ)) {
                errorStrs.add("第 " + (j + 1) + " 行的 roleCode 值:" + roleCodeI + " 已存在,忽略导入");
                listSysRoles.remove(j);
                break;
            }
        }
    }
    // 去掉 sql 中的重复数据
    Integer errorLines=0;
    Integer successLines=0;
    List<String> list = ImportExcelUtil.importDateSave(listSysRoles, ISysRoleService.class, errorStrs, CommonConstant.SQL_INDEX_UNIQ_SYS_ROLE_CODE);
     errorLines+=list.size();
     successLines+=(listSysRoles.size()-errorLines);
    return ImportExcelUtil.imporReturnRes(errorLines,successLines,list);
}