diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d34efd7..ad080878e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ------------------------------------------------------------------------------------------------------------- -# 5.7.15 (2021-10-15) +# 5.7.15 (2021-10-16) ### 🐣新特性 * 【db 】 Db.quietSetAutoCommit增加判空(issue#I4D75B@Gitee) @@ -16,6 +16,7 @@ * 【core 】 修复CollUtil.isEqualList两个null返回错误问题(issue#1885@Github) * 【poi 】 修复ExcelWriter多余调试信息导致的问题(issue#1884@Github) * 【poi 】 修复TemporalAccessorUtil.toInstant使用DateTimeFormatter导致问题(issue#1891@Github) +* 【poi 】 修复sheet.getRow(y)为null导致的问题(issue#1893@Github) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelReader.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelReader.java index 80dfb4e4d..301d39309 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelReader.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/ExcelReader.java @@ -281,11 +281,13 @@ public class ExcelReader extends ExcelBase { short columnSize; for (int y = startRowIndex; y <= endRowIndex; y++) { row = this.sheet.getRow(y); - columnSize = row.getLastCellNum(); - Cell cell; - for (short x = 0; x < columnSize; x++) { - cell = row.getCell(x); - cellHandler.handle(cell, CellUtil.getCellValue(cell)); + if(null != row){ + columnSize = row.getLastCellNum(); + Cell cell; + for (short x = 0; x < columnSize; x++) { + cell = row.getCell(x); + cellHandler.handle(cell, CellUtil.getCellValue(cell)); + } } } } 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 4326a8608..ebe04bf0f 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 @@ -4,6 +4,7 @@ import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.lang.Console; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.poi.excel.cell.CellHandler; import lombok.Data; import org.junit.Assert; import org.junit.Ignore; @@ -225,4 +226,11 @@ public class ExcelReadTest { final List> maps = reader.readAll(); Console.log(maps); } + + @Test + @Ignore + public void readNullRowTest(){ + final ExcelReader reader = ExcelUtil.getReader("d:/test/1.-.xls"); + reader.read((CellHandler) Console::log); + } }