我正在使用Poi.jar从excel工作表中获取输入,想知道如何检查单元格是否为空。
现在我正在使用下面的代码。
cell = myRow.getCell(3);
if (cell != null) {
cell.setCellType(Cell.CELL_TYPE_STRING);
//System.out.print(cell.getStringCellValue() + "\t\t");
if (cell.getStringCellValue() != "")
depend[p] = Integer.parseInt(cell.getStringCellValue());
}
}
发布于 2013-04-03 13:21:17
如果您使用的是Apache POI 4.x,则可以使用:
Cell c = row.getCell(3);
if (c == null || c.getCellType() == CellType.Blank) {
// This cell is empty
}
对于早于迁移到CellType
枚举之前的Apache POI3.x版本,它是:
Cell c = row.getCell(3);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
// This cell is empty
}
但是,不要忘记检查Row
是否为null --如果从未使用过没有使用过单元格或样式的行,则该行本身可能为null!
发布于 2018-04-25 01:04:57
从Apache POI 3.17开始,您必须使用枚举检查单元格是否为空:
import org.apache.poi.ss.usermodel.CellType;
if(cell == null || cell.getCellTypeEnum() == CellType.BLANK) { ... }
发布于 2018-02-19 17:35:21
Cell cell = row.getCell(x, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
这个技巧帮了我很多,看看对你有没有用
https://stackoverflow.com/questions/15764417
复制相似问题