fix null bug

This commit is contained in:
Looly
2021-10-16 00:27:13 +08:00
parent 3ed26fe761
commit 644d1c22c7
3 changed files with 17 additions and 6 deletions

View File

@@ -281,11 +281,13 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
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));
}
}
}
}

View File

@@ -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<Map<String, Object>> 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);
}
}