EasyXLS

How to read Excel file in C# and VB.NET

Concept

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

Concept in action

The below example shows how to read Excel file in C# and VB.NET.

Source code sample

C#.NET
VB.NET

Read Excel file having one sheet

Reading data from Excel file, if the Excel file has only one sheet, is the easiest approach. The Excel data can be read with one single line of code using:
- ExcelDocument.easy_ReadXLSActiveSheet_AsDataSet method for XLS file
- ExcelDocument.easy_ReadXLSXActiveSheet_AsDataSet method for XLSX file
- ExcelDocument.easy_ReadXLSBActiveSheet_AsDataSet method for XLSB file

The above code sample shows how to achieve this goal.

Read Excel file having multiple sheets

There are three approaches for reading data from an Excel file with multiple sheets.

I. Usually the first sheet is the active sheet inside an Excel file. If this is your case or if you are reading data from another active sheet use:
- ExcelDocument.easy_ReadXLSActiveSheet_AsDataSet method for XLS file
- ExcelDocument.easy_ReadXLSXActiveSheet_AsDataSet method for XLSX file
- ExcelDocument.easy_ReadXLSBActiveSheet_AsDataSet method for XLSB file

II. For reading data from an Excel sheet and the name of the sheet is known, EasyXLS recommends the use of:
- ExcelDocument.easy_ReadXLSSheet_AsDataSet method for XLS file
- ExcelDocument.easy_ReadXLSXSheet_AsDataSet method for XLSX file
- ExcelDocument.easy_ReadXLSBSheet_AsDataSet method for XLSB file

III. For reading data from an Excel sheet and the name of the sheet is not known, the first step is to find the sheet by reading the entire Excel file using:
- ExcelDocument.easy_LoadXLSFile method for XLS file
- ExcelDocument.easy_LoadXLSXFile method for XLSX file
- ExcelDocument.easy_LoadXLSBFile method for XLSB file

Then, read the sheet data in Dataset using ExcelDocument.easy_ReadExcelWorksheet_AsDataSet method.

Read range of Excel cells

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.

Read XLSX, XLSB, XLSM and XLS files

This code sample shows how to read XLS file. In a similar way, you can read XLSX, XLSM, XLSB files using:
- ExcelDocument.easy_ReadXLSXActiveSheet_AsDataSet or ExcelDocument.easy_ReadXLSXSheet_AsDataSet method for XLSX and XLSM files
- ExcelDocument.easy_ReadXLSBActiveSheet_AsDataSet or ExcelDocument.easy_ReadXLSBSheet_AsDataSet method for XLSB files

Read Excel file into DataTable

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.

Read Excel file into DataSet

EasyXLS allows reading an Excel file into a DataSet. The above code sample shows how to achive this goal. For more code samples see the below link.

Read Excel file and insert data into SQL database

EasyXLS allows reading an Excel file. The data from the Excel sheet can be inserted into SQL table.

Getting started with EasyXLS Excel library

To download the trial version of EasyXLS Excel Library, press the below button:

Download EasyXLS™ Excel Library for .NET

If you already own a license key, you may login and download EasyXLS from your account.

After installation, you will need to create a C# or VB.NET project and add a reference to EasyXLS.dll.



Available for: Professional, Excel Reader
Go to top

EasyXLS Excel libraries:

.NET
.NET Excel Library
full .NET version to import, export or convert Excel files
.NET Excel Reader
.NET version to read and import Excel files
Download EasyXLS™ Excel Library for .NET

File formats:

MS Excel 97
MS Excel 2003
MS Excel 2007
MS Excel 2010
MS Excel 2013
MS Excel 2016
XLS XLSX XLSM XLSB
XML HTML CSV TXT