Opening the document

Once the file is opened, we have to store the data - this is done using an WorkBook object. This method has lots of arguments, fortunately only the first is required (which is the file’s path) - so we can add Type.Missing to the others:

Reading the data

Now, as you probably know, an Excel document contains multiple WorkSheets. To read a cell’s value, we have to select the WorkSheet where the cell is found:

1
2
3
4
5
6
7
8
9
10

Sheetsworksheets=wbook.Worksheets;//storing all the sheets
Rangecell=((Worksheet)worksheets["Sheet1"]).get_Range("A1","A1");//from the worksheets, we select Sheet1 and then the cell A1
stringcell_value=cell.Value.ToString();//this is the cell's value
/* some-code */wbook.Close();//closing...

Result

That’s all you might need to know about how to read an Excel document with C#.
I wrote a small application which shows the content of a Excel file, using a dataGridView.