easyExcel多sheet页导入

/**
 * Description: 获取日前交易excel数据
 *
 * @param file
 * @return
 */
private Map<String,List<SpotDailyDealImportVO>> SpotDailyDealLoadExcelData(MultipartFile file){



    Map<String,List<SpotDailyDealImportVO>> map = new HashMap<>();
    try {
        //获取所有sheet页
        List<ReadSheet> readSheets = ExcelImportHelper.listSheet(file.getInputStream());
        List<ReadSheet> arrayList = readSheets.stream().collect(
                // 将集合先放到 treeSet去重,然后将他们转换成list
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getSheetName())))
                        , ArrayList::new));
        if (arrayList.size() < readSheets.size()){
            throw new BusinessException("存在相同机组名称!");
        }
        if (ObjectUtils.isNotEmpty(readSheets)){
            //读取数据
            int i = 0;//从第一页开始读
            for (ReadSheet readSheet : readSheets){
                map.put(readSheet.getSheetName(),ExcelImportHelper.loadExcelDataFully(
                        ExcelImportHelper.getExcelTypeByName(file.getOriginalFilename()), file.getInputStream(), i ,
                        MagicNumConstant.ONE, SpotDailyDealImportVO.class));
                i++;
            }
        }else throw new BusinessException("无法获取到sheet页信息!");
    } catch (IOException e) {
        log.error("error",e);
        throw new BusinessException("上传文件格式不正确" + e.getMessage());
    }
    if (map.size() == 0){
        throw new BusinessException("数据异常,没有数据!");
    }

    return map;
}

工具类

/*
 * Project Name: fsc
 * File Name: ExcelImportHelper.java
 * Class Name: ExcelImportHelper
 *
 * Copyright 2018 Hengtian Software Inc
 *
 * Licensed under the Hengtiansoft
 *
 * http://www.hengtiansoft.com
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KI
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值