fix expty excel bug

This commit is contained in:
Looly 2021-05-08 10:34:59 +08:00
parent 7c866e10e0
commit 79e7fe93f6
3 changed files with 13 additions and 0 deletions

View File

@ -12,6 +12,7 @@
### 🐞Bug修复
* 【core 】 修复createScheduledExecutor单位不是毫秒的问题issue#I3OYIW@Gitee
* 【core 】 修复Tailer无stop问题issue#I3PQLQ@Gitee
* 【core 】 修复空白excel读取报错问题issue#1552@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -2,6 +2,7 @@ package cn.hutool.poi.excel.reader;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import org.apache.poi.ss.usermodel.Sheet;
@ -36,6 +37,10 @@ public class MapSheetReader extends AbstractSheetReader<List<Map<String, Object>
// 边界判断
final int firstRowNum = sheet.getFirstRowNum();
final int lastRowNum = sheet.getLastRowNum();
if(lastRowNum < 0){
return ListUtil.empty();
}
if (headerRowIndex < firstRowNum) {
throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is lower than first row index {}.", headerRowIndex, firstRowNum));
} else if (headerRowIndex > lastRowNum) {

View File

@ -217,4 +217,11 @@ public class ExcelReadTest {
Assert.assertEquals("#", read.get(3).get(0));
Assert.assertEquals("#", read.get(3).get(1));
}
@Test
public void readEmptyTest(){
final ExcelReader reader = ExcelUtil.getReader("d:/test/issue.xlsx");
final List<Map<String, Object>> maps = reader.readAll();
Console.log(maps);
}
}