Before未定义异常情况
![](https://img-blog.csdnimg.cn/img_convert/e203ae0b15e751de78c041630f113048.png)
![](https://img-blog.csdnimg.cn/img_convert/2a9d2f28bdd06a95b6b751b9f7d9af45.png)
继承 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
![](https://img-blog.csdnimg.cn/img_convert/a9ecacf5a09d01f5b7df14b82c87cb90.png)