public void ExcelHelper(string fileName)
{
object misval = System.Reflection.Missing.Value;
Excel.Application excelApp = new Excel.Application();
if (excelApp != null)
{
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(fileName, misval, misval, misval, misval, misval, misval, misval, misval, misval, misval, misval, misval);
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelWorkbook.Sheets[1];
Excel.Range excelRange = excelWorksheet.UsedRange;
int rowCount = excelRange.Rows.Count;
int colCount = excelRange.Columns.Count;
for (int i = 1; i <= rowCount; i++)
{
for (int j = 1; j <= colCount; j++)
{
Excel.Range range = (excelWorksheet.Cells[i, 1] as Excel.Range);
string cellValue = range.Value.ToString();
Console.WriteLine(cellValue);
//do anything
}
}
excelWorkbook.Close();
excelApp.Quit();
}
}
Follow Us
Were this world an endless plain, and by sailing eastward we could for ever reach new distances