add a reference to C:\Windows\assembly\GAC\Microsoft.Office.Interop.E xcel\12.0.0.0__71e9bce111e9429c\Microsoft.Office.I nterop.Excel.dll
you may need to install https://www.microsoft.com/en-us/down....aspx?id=13255 but i'm not sure
string filePath2 = "file.xlsx";
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(filePath2);
Excel._Worksheet xlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
Excel.Range startCell = (Excel.Range)xlWorksheet.Cells[1, 1];
Excel.Range endCell = (Excel.Range)xlWorksheet.Cells[rowCount, colCount];
Excel.Range range = xlWorksheet.Range[startCell, endCell];//worksheet.get_Range("A" + i.ToString(), "J" + i.ToString());
System.Array myvalues = (System.Array)range.Cells.Value;
for (int j = 1; j < rowCount; j++)
{
for (int i = myvalues.GetLowerBound(0); i < myvalues.GetUpperBound(1); i++)
{
Print(myvalues.GetValue(j,i));
}
}
GC.Collect();
GC.WaitForPendingFinalizers();
//close and release
xlWorkbook.Close();
//quit and release
xlApp.Quit();

Comment