I have a huge excel file with tons of columns which looks like this :-
Column1 Column2 Column3 Column4 Column5
abc def ghi
mn
for(org.apache.poi.ss.usermodel.Row tmp : hssfSheet){
for(int i = 0; i<8;i++){
System.out.println(tmp.getCell(i));
}
}
for (Row row: sheet){
// This will return null if cell is empty / blank
Cell cell = row.getCell(columnNumber);
}
If you want to get all cells, no matter if they exist or not, then the iterator isn't for you. Instead, you need to manually fetch the appropriate cells, likely with a missing cell policy
for(Row row : sheet) {
for(int cn=0; cn<row.getLastCellNum(); cn++) {
// If the cell is missing from the file, generate a blank one
// (Works by specifying a MissingCellPolicy)
Cell cell = row.getCell(cn, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
// Print the cell for debugging
System.out.println("CELL: " + cn + " --> " + cell.toString());
}
}
There's more details on all of this in the Apache POI documentation on iterating over cells