EasyExcel导入类型转换错误自定义异常

Before未定义异常情况

继承 AnalysisEventListener 重写 onException

@Override
    public void onException(Exception exception, AnalysisContext context) throws Exception {
        if (exception instanceof ExcelDataConvertException) {
            ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception;
            Integer row = excelDataConvertException.getRowIndex()+ 1;
            Integer column = excelDataConvertException.getColumnIndex()+1;
            throw new RuntimeException("第"+row+"行,第"+column+"列解析异常,请正确填写");
        }
    }

当抛出异常,停止读剩余数据,直接返回。

当没有抛出异常,忽略此行,继续读取插入

After

猜你喜欢

转载自blog.csdn.net/zjy660358/article/details/129020470