easyexcel空的问题

我们在用阿里巴巴的Excel组件解析excel的时候, 会出现表头和内容列数不一致的情况, 采用以下方式就可以了 public class EasyExcelDemo {

private static String getCellValue(final Object value){
    if(value==null){
        return "";
    }
    return value.toString();
};
public static void main(String[] args) {

    ExcelListener excelListener = new ExcelListener();
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(new File("D:\\更新mingjian.xlsx"));
        EasyExcelFactory.readBySax(inputStream, new Sheet(1, 0), excelListener);
        inputStream.close();
        List<List<String>> list = excelListener.list;
        //获取表头的size
        int size = list.get(0).size();
        //移除表头
        list.remove(0);
        //声明一个数组, 是excel列, 要保持列数
        Object[] cells = new Object[size];

        Object cell = cells[5];
        
        //解析内容
        for (int i = 0; i < list.size(); i++) {
            List<String> strings = list.get(i);
            if(strings.size()!=size){
                System.arraycopy(strings.toArray(),0,cells,0, strings.toArray().length);
            }else{
                cells = strings.toArray();
            }

            String dAttr = getCellValue(cells[0]);
            String problem_code = getCellValue(cells[1]);
            String key_problem = getCellValue(cells[2]);
            String standard = getCellValue(cells[3]);
            String check_time = getCellValue(cells[4]);
            String dCode = getCellValue(cells[5]);
            String is_score = getCellValue(cells[6]);
            String loss_score_reason = getCellValue(cells[7]);
            
            System.out.println();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

转载于:https://my.oschina.net/maxj/blog/3084831

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值