Skip to content

Conversation

@nramsbottom
Copy link

I received an Excel file that could not be opened because it caused a crash. After some debugging I determined that it is because the v element within a c element doesn't have a value and the existing code expects there to always be a value.

image

The file was generated by an external vendor, so I cannot alter how it is generated. The file can be opened by Excel and LibreOffice Calc with no issues.

I have produced a sample of the "broken" file here.

Book1.xlsx

This fix ensures that the shared string index is read as a string and parsed safely and the appropriate content placed into the cell.

@nramsbottom
Copy link
Author


using OfficeOpenXml;

using var fileStream = File.OpenRead(@"..\..\..\..\Book1.xlsx");
using var package = new ExcelPackage(fileStream);

var workSheet = package.Workbook.Worksheets.FirstOrDefault();
var rowCount = workSheet.Dimension.End.Row;

Console.WriteLine($"{rowCount} rows.");
Console.ReadKey();

Sample code I used to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant