I am having an issue with a particular spreadsheet. The code below has been working great for many spreadsheets. On this particular sheet, it dies when it hits the foreach
and attempts to access package.Workbook.Worksheets
.
protected void ParseExcelFile(Stream stream)
{
var package = new ExcelPackage(stream);
foreach (var sheet in package.Workbook.Worksheets.Where(s => CategoryTabNames.IsCategoryTabName(s.Name)))
{
//doing things
}
}
If I look at the Worksheets property in Visual Studio, it says
System Argument Exception
When the thrown exception is caught by the calling method, the exception message is
Requested value 'baseline' was not found.
I'm at a bit of a loss on where to go next. The file is able to be opened by Excel fine. Thanks for the help.
So it turns out the issue is how EPPlus handles vertical alignment. According to the spec for Open Office XML, "baseline" should be an acceptable value for vertical alignment. However EPPlus doesn't handle this, so it throws the exception. We issued a push request to the devs explaining the issue with the fix.
I think we didn't run into this issue before because baseline is potentially the same as none or blank. I am thinking the Sharepoint Excel editor which is typically used by the app users would simply leave it blank, but someone must have edited the sheet with an Excel editor that used this "baseline" value instead.