User GuideFAQHow to read Excel file in C# and VB.NET
How to read Excel file in C# and VB.NET
EasyXLS™ library allows you to read data from Excel file. The data can be read from an Excel sheet or from the active Excel sheet. The entire sheet data or only data from ranges of cells can be read.
EasyXLS can be successfully used to also read large Excel files having big volume of data with fast reading time.
EasyXLS permits you to read Excel files without Excel installed, without Interop, without OLEDB or any other additional software installed.
The source code samples can be integrated in:
- ASP.NET web pages - Windows applications - Windows Forms (WinForms) - Console applications - Windows service applications - ASP.NET MVC web applications
// Create an instance of the class that reads Excel files
ExcelDocument workbook = new ExcelDocument();
// Read Excel file to DataSet
DataSet dataSet = workbook.easy_ReadXLSXActiveSheet_AsDataSet("C:\\Samples\\Excel file.xlsx");
// Display DataSet values
DataTable dataTable = dataSet.Tables[0];
for (int row=0; row < dataTable.Rows.Count; row++)
for (int column=0; column < dataTable.Columns.Count; column++)
Console.WriteLine("At row " + (row + 1) + ", column " + (column + 1) + " the value is '" +
dataTable.Rows[row].ItemArray[column] + "'");
' Create an instance of the class that reads Excel filesDim workbook As New ExcelDocument
' Read Excel file to DataSetDim ds As DataSet = workbook.easy_ReadXLSXActiveSheet_AsDataSet("C:\Samples\Excel file.xlsx")
' Display DataSet valuesDim dataTable As DataTable = ds.Tables(0)
For row As Integer = 0 To dataTable.Rows.Count - 1
For column As Integer = 0 To dataTable.Columns.Count - 1
Console.WriteLine("At row " & (row + 1) & ", column " & (column + 1) & _
" the value is '" & dataTable.Rows(row).ItemArray(column) & "'")
Next
Next
EasyXLS enables you to read data from Excel file either from the entire sheet or from a range of cells. Reading only a range of cells is a very useful option especially for large Excel files because it reduces the speed of the reading process.
In order to read multiple cell ranges at once from Excel sheet, the range parameter must be passed to the method as union of ranges (multiple ranges separated by comma).
All the methods that allow reading Excel sheets have parameters that permit reading data only from ranges of cells.
EasyXLS allows reading an Excel file into a DataTable. The DataTable can be used as data source of a GridView, DataGridView, DataGrid or for any other purposes.