11,570 questions
My recommendation is to avoid Excel automation and use a library such as SpreadSheetLight (free)
Simple starter code
public static void Example(string fileName, string sheetName)
{
using (var document = new SLDocument(fileName, sheetName))
{
var stats = document.GetWorksheetStatistics();
for (int rowIndex = 1; rowIndex < stats.EndRowIndex + 1; rowIndex++)
{
for (int columnIndex = 1; columnIndex < stats.EndColumnIndex +1; columnIndex++)
{
Console.WriteLine($"{SLConvert.ToCellReference(rowIndex, columnIndex)} = {document.GetCellValueAsString(rowIndex, columnIndex)}");
}
}
}
}