Closed
Description
版本号:2.2
问题描述:
经测试,
jeecgController 类 第 101行 (如下图1) ImportParams setTitleRows=2
ExcelImportServer类 第250行 (如下图2)中的getTitleMap方法中 使用循环判断了起始行,该循环获取了ImportParams的titleRows作为headBegin变量的初始值.如果headRow为null就执行循环,循环结束后获取第headBegin行赋值给headRow,.如果excel文件的总行数小于3行,那么headRow初始值为2,sheet.getRow(headBegin++)永远为null,就会造成死循环.
建议修改方案:
建议判断文件内容起始行,读取每行第一个参数和反射中的类的每个字段的@Excel注解的name值做比对,如果比对上了,就基本可以认定为其实行.
最起码要判断一下文件总行数,ImportParams的titleRow肯定不能大于文件总行数,否则就死循环,如果文件总行数为0.就直接退出.
截图&代码:
友情提示: 未按格式要求发帖,会直接删掉。
Activity
tygithub1 commentedon Jun 22, 2020
添加代码:

int allRowNum = sheet.getPhysicalNumberOfRows(); for(headBegin = params.getTitleRows(); headRow == null && headBegin < allRowNum; headRow = sheet.getRow(headBegin++)) { } if(headRow==null){ throw new Exception("不识别该文件"); }
效果图:
javaAjun commentedon Jun 22, 2020
这个逻辑对的,判断下总行数就不会死循环了