How to read huge Excel file using C#

Reading a Excel file is easy using the SpreadsheetDocument and SheetData classes but this method uses a lot of memory if the Excel file is big.
This is due to the fact that to get the sheet data the framework loads the entire file into memory.

To read huge files it is better to use the OpenXmlReader.

Here’s an example usage of the OpenXmlReader (it also consider the SharedString)

To loop the Excel’s rows

The OpenXmlReader uses less memory, but it is slow.
For faster reading you can use the ExcelDataReader, it is available also as a NuGet package.