Fix 读取空行NPE错误

This commit is contained in:
jin.huang 2022-04-01 17:53:53 +08:00
parent 0986e60a7c
commit bffd1d204c
3 changed files with 12 additions and 0 deletions

View File

@ -203,6 +203,9 @@ public class CellUtil {
* @since 5.5.0 * @since 5.5.0
*/ */
public static Cell getCell(Row row, int cellIndex) { public static Cell getCell(Row row, int cellIndex) {
if (null == row) {
return null;
}
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);
if (null == cell) { if (null == cell) {
return new NullCell(row, cellIndex); return new NullCell(row, cellIndex);
@ -219,6 +222,9 @@ public class CellUtil {
* @since 4.0.2 * @since 4.0.2
*/ */
public static Cell getOrCreateCell(Row row, int cellIndex) { public static Cell getOrCreateCell(Row row, int cellIndex) {
if (null == row) {
return null;
}
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);
if (null == cell) { if (null == cell) {
cell = row.createCell(cellIndex); cell = row.createCell(cellIndex);

View File

@ -244,4 +244,10 @@ public class ExcelReadTest {
Assert.assertEquals("李四", objects.get(1)); Assert.assertEquals("李四", objects.get(1));
Assert.assertEquals("", objects.get(2)); Assert.assertEquals("", objects.get(2));
} }
@Test
public void readColumnNPETest() {
ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("read_row_npe.xlsx"));
reader.readColumn(0, 1);
}
} }

Binary file not shown.