How to use NPOI to read Excel spreadsheet that contains empty cells?
Try the GetCell
method with the MissingCellPolicy
:
ICell cell = row.GetCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK);
In completion to the accepted answer, the policy can be set on the workbook level as well
workbook.MissingCellPolicy = MissingCellPolicy.RETURN_NULL_AND_BLANK;
This way the policy is applied implicitly when you call GetCell
, no need to pass it every time as a parameter
ICell cell = row.GetCell(2);
Note that (at least in the version I'm using) if you do row.Cells[index]
, it ignores the policy so it only works if you call row.GetCell(index)