How to read Excel cell having null values too in Java...?
I've finally got what I want. I thank mezmo for it. I want to share the exact code snippet to be changed. Just replace the line having :
HSSFCell cell = row.getCell(c);
with
HSSFCell cell=row.getCell(c, org.apache.poi.ss.usermodel.Row.CREATE_NULL_AS_BLANK );
Well, you could check for null before your switch statement, or you could change which call to row.getCell you make. Checking the Javadoc for POI there are 2 forms, the first is what you are using, the second has an additional parameter, of the type Row.MissingCellPolicy, where you can pass a value that would automagically transform null cells into blanks.
You need to check if cell!=null
, because if a cell doesn't exist in a row, row.getCell(c)
returns null