Microsoft.Office.Interop.Excel

using Excel = Microsoft.Office.Interop.Excel;

var excel = new Excel.Application();
excel.Visible = false; //to hide the processing
Excel.Workbook wb = excel.Workbooks.Open(fileName);
Excel.Worksheet sheet = (Excel.Worksheet)wb.Sheets[1];//[“Keyword”];
var xlRange = sheet.UsedRange;

int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
sheet.Columns.NumberFormat = Excel.XlColumnDataType.xlTextFormat;

for (int i = 2; i < rowCount; i++)
{
for (int j = 1; j <= colCount; j++)
{
//((Excel.Range)xlWks.Cells[r, c]).NumberFormat = format;
var ceva = (xlRange.Cells[i, j] as Excel.Range).Value2;//sheet.Cells[i, j].ToString();
}
}

//cleanup
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.ReleaseComObject(xlRange);
Marshal.ReleaseComObject(sheet);
//close and release
wb.Close();
Marshal.ReleaseComObject(wb);
//quit and release
excel.Quit();
Marshal.ReleaseComObject(excel);

Advertisements