Yes, it is possible to verify if a cell value is either empty or null using Apache POI.
Here is an example code snippet:
Cell cell = row.getCell(columnIndex);
if(cell == null || cell.getCellType() == CellType.BLANK){
// cell is either null or empty
}
In this code, we first check if the cell reference is null. If it is null, then the cell is considered empty. We also check if the cell type is BLANK
. If the cell type is blank, then the cell is also considered empty.
Note that if a cell contains a formula that evaluates to an empty string, it will still be considered non-empty. In that case, you can use the cell.getStringCellValue()
method and check if the returned value is an empty string.
Asked: 2021-08-21 11:00:00 +0000
Seen: 21 times
Last updated: Apr 10 '23