栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

工具集合-上传excel的util

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

工具集合-上传excel的util

import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;



@Data
public class UploadAccountDto {

    //name表头、fixedindex列下标
    @Excel(name = "应用系统",fixedIndex = 0)
    private String applicationSystem;

    @Excel(name = "应用从账号名称",fixedIndex = 1)
    private String accountSon;

    @Excel(name = "应用侧从账号姓名",fixedIndex = 2)
    private String accountSonRealName;

    @Excel(name = "应用账号状态",fixedIndex = 3)
    private String accountSonStatus;

    @Excel(name = "加锁原因",fixedIndex = 4)
    private String accountSonLockCause;

    @Excel(name = "从账号加锁时间",fixedIndex = 5)
    private String accountSonLockTime;

    @Excel(name = "从账号创建时间",fixedIndex = 6)
    private String accountSonCreatorTime;

    @Excel(name = "从账号最后更新时间",fixedIndex = 7)
    private String accountSonLastUpdateTime;

    @Excel(name = "从账号最后登录时间",fixedIndex = 8)
    private String accountSonLastLoginTime;

    @Excel(name = "授权生效时间",fixedIndex = 9)
    private String accountMasterEmpowerStartTime;

    @Excel(name = "授权失效时间",fixedIndex = 10)
    private String accountMasterEmpowerEndTime;

    @Excel(name = "账号类型",fixedIndex = 11)
    private String accountType;

    @Excel(name = "归属主账号",fixedIndex = 12)
    private String accountMaster;

    @Excel(name = "主账号姓名",fixedIndex = 13)
    private String accountMasterRealName;

    @Excel(name = "组织机构",fixedIndex = 14)
    private String institution;

    @Excel(name = "归属部门",fixedIndex = 15)
    private String belongingDept;

    @Excel(name = "主账号状态",fixedIndex = 16)
    private String accountMasterStatus;

    @Excel(name = "加锁类型",fixedIndex = 17)
    private String accountMasterLockType;

    @Excel(name = "主账号加锁原因",fixedIndex = 18)
    private String accountMasterLockCause;

    @Excel(name = "主账号加锁时间",fixedIndex = 19)
    private String accountMasterLockTime;

    @Excel(name = "主账号创建时间",fixedIndex = 20)
    private String accountMasterCreatorTime;

    @Excel(name = "主账号密码策略",fixedIndex = 21)
    private String accountMasterPwdStrategy;

    @Excel(name = "密码最后更新时间",fixedIndex = 22)
    private String accountMasterLastUpdateTime;

    @Excel(name = "账号到期时间",fixedIndex = 23)
    private String accountMasterAbortTime;

}

需求是这样的,前端点击上传excel,后台读取并存入数据库,上面这个类是辅助类,name和下表设置好了,

  @PostMapping("/accInfo/uploadContrast")
    public Result accInfoUploadContrast(@RequestParam("file") MultipartFile file) throws IOException {

        ImportParams importParams = new ImportParams();
        importParams.setHeadRows(1);
        importParams.setTitleRows(0);
        importParams.setVerifyFileSplit(false);

        //流校验文件
        InputStream stream = new BufferedInputStream(file.getInputStream());
        if (!ExcelFileUtil.isXlsx(stream)){
            return new Result().error("-1", "文件类型错误");
        }

        try {
            //读取并转换
            ExcelImportResult result =
                            ExcelImportUtil.importExcelMore(file.getInputStream(),UploadAccountDto.class, importParams);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return new Result();

    }
}

然后把流、类型传进去就可以获得一个list了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/933466.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号