I have excel file with sheet1 that has a value I need to read on row 2 and column 10. Here is my code.
Excel.Workbook excelWorkbook = excelApp.Workbooks.Ope
The issue with reading single Excel Cell in .Net comes from the fact, that the empty cell is evaluated to a Null. Thus, one cannot use its .Value or .Value2 properties, because an error shows up.
To return an empty string, when the cell is Null the Convert.ToString(Cell) can be used in the following way:
Excel.Workbook wkb = Open(excel, filePath);
Excel.Worksheet wk = (Excel.Worksheet)excel.Worksheets.get_Item(1);
for (int i = 1; i < 5; i++)
{
string a = Convert.ToString(wk.Cells[i, 1].Value2);
Console.WriteLine(a);
}