I'm a hobbyist trying to read an Excel file in order to change its format.
I want to look at columnIndex(0)
to see if there is any text, if there is there are items at index (2–4) through row (+1 – 3) from that cell which I need to copy (never mind that, it's not the problem).
However, there are a lot of empty cells at columnIndex(0)
which throw a NullPointerException
because they 'don't exist'. I've been trying several cell checks using (cell == null)
and .getCellTypeEnum
etc. None seem to work.
Do you guys has any tips on how to circumvent this?
My staring code below:
// loading stuff
int row = 0;
int rowTot = sheet.getLastRowNum();
while (row < rowTot) {
for (Cell cell : sheet.getRow(row)) {
if (cell.getColumnIndex() == 0) {
if (cell == null) {
System.out.println("empty");
} else {
String text = cell.getStringCellValue();
System.out.println(text);
}
}
}
row++;
// closing