diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ba379aaf..215eb506d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### 🐞Bug修复 * 【core 】 修复createScheduledExecutor单位不是毫秒的问题(issue#I3OYIW@Gitee) * 【core 】 修复Tailer无stop问题(issue#I3PQLQ@Gitee) +* 【core 】 修复空白excel读取报错问题(issue#1552@Github) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/reader/MapSheetReader.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/reader/MapSheetReader.java index 5396c3583..0f832597d 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/reader/MapSheetReader.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/reader/MapSheetReader.java @@ -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 // 边界判断 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) { diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java index 3fc73a029..839d50224 100644 --- a/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/ExcelReadTest.java @@ -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> maps = reader.readAll(); + Console.log(maps); + } }