Merge pull request #2234 from goldpumpkin/v5-dev

读取 excel 抛 NPE 错误
This commit is contained in:
Golden Looly 2022-04-02 00:38:46 +08:00 committed by GitHub
commit aaa88dad81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -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);

View File

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

Binary file not shown.