January 24th, 2015

NPOI Excel C# Library & Missing Columns

Here's a quick one we found that wasn't that obvious and may help some other developers save a bit of time. The C# NPOI library for Microsoft Excel defaults to not parse null and blank columns, so when iterating over rows each with 15 columns you may get the value 14 back from Row.Cells.Count

You can however return the correct number of fields by using the property Row.PhysicalNumberOfCells and access the values by using the method Row.GetCell(1, MissingCellPolicy.CREATE_NULL_AS_BLANK).

Happy coding!

comments powered by Disqus