diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java index 171106b59..f4747bae3 100644 --- a/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java +++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/cell/CellUtil.java @@ -203,6 +203,9 @@ public class CellUtil { * @since 5.5.0 */ public static Cell getCell(Row row, int cellIndex) { + if (null == row) { + return null; + } Cell cell = row.getCell(cellIndex); if (null == cell) { return new NullCell(row, cellIndex); @@ -219,6 +222,9 @@ public class CellUtil { * @since 4.0.2 */ public static Cell getOrCreateCell(Row row, int cellIndex) { + if (null == row) { + return null; + } Cell cell = row.getCell(cellIndex); if (null == cell) { cell = row.createCell(cellIndex); 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 72ac31fab..22f1ba075 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 @@ -244,4 +244,10 @@ public class ExcelReadTest { Assert.assertEquals("李四", objects.get(1)); Assert.assertEquals("", objects.get(2)); } + + @Test + public void readColumnNPETest() { + ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("read_row_npe.xlsx")); + reader.readColumn(0, 1); + } } diff --git a/hutool-poi/src/test/resources/read_row_npe.xlsx b/hutool-poi/src/test/resources/read_row_npe.xlsx new file mode 100644 index 000000000..662ef950b Binary files /dev/null and b/hutool-poi/src/test/resources/read_row_npe.xlsx differ