0

I am attempting to use the ExcelWriter class to read the contents of an uploaded Excel file in a way where the code will process the data in any of the workbook's worksheets.

So something like this:

foreach (var worksheet in workbook.Worksheets)
{
    var area = worksheet.PopulatedCells;
    if (area == null)
        break;

    ...do stuff with the cells in the area...
}

The problem is that when I call Worksheet.PopulatedCells I get an exception thrown saying that there aren't any populated cells when the worksheet is empty rather than returning me null.

Is there some way to detect if a Worksheet is empty?

Christopher King
  • 1,691
  • 23
  • 28
  • Given that the worksheet is empty, what is the value of `area` being set to? Put a break point on your `if (area == null)` line and check the value of `area`. – HappyCoding Jul 11 '16 at 18:38
  • 1
    It's not getting set to anything if that line throws an exception. – Scott Hannen Jul 11 '16 at 18:57
  • This is not the most helpful answer, but perhaps you should switch to [EPPlus](http://epplus.codeplex.com/). The documentation pages for ExcelWriter are giving me error messages and they all say "copyright 2009". That doesn't inspire confidence. That and the error you're reporting. – Scott Hannen Jul 11 '16 at 18:59

0 Answers0