EasyXLS

How to import Excel file to GridView in C# and VB.NET

EasyXLS™ library allows you to import Excel data to GridView. The data can be imported from an Excel sheet or from the active Excel sheet. The entire sheet data or only data from ranges of cells can be imported.

EasyXLS can be successfully used to also import large Excel files having big volume of data with fast importing time.

EasyXLS permits you to import Excel files without Excel installed, without OLEDB, without Interop or any other additional software installed.

Source code sample

Step 1: Download and install EasyXLS Excel Library for .NET

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.

Step 2: Create a C# or VB.NET project

If don't have a project, create one as ASP.NET web application, windows forms app, console application, class library or service.

Step 3: Include EasyXLS library into project

EasyXLS.dll must be added as reference to your project. EasyXLS.dll can be found after installing EasyXLS, in "Dot NET version" folder.

Add EasyXLS reference

Step 4: Run C# or VB.NET code that imports Excel data to GridView

The below example shows how to import Excel data to GridView in C# and VB.NET from a winform windows application.

C#.NET
VB.NET

Import Excel cell formatting to GridView

Importing also the cell formatting requires some changes to previous code in order to import not only data from the Excel file, but also the cell formatting styles. See below how the source code must be adjusted:

Source code sample

C#.NET
VB.NET

EasyXLS also offers some open source code that imports an Excel file to a GridView. The code shows how to import all cell data and formatting, conditional formatting and the charts.

Import Excel file having one sheet to GridView

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

The first code sample shows how to achieve this goal.

Import Excel file having multiple sheets to GridView

There are three approaches for importing 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 importing data from another active sheet use:
- ExcelDocument.easy_ReadXLSXActiveSheet_AsDataSet method for XLSX file
- ExcelDocument.easy_ReadXLSBActiveSheet_AsDataSet method for XLSB file
- ExcelDocument.easy_ReadXLSActiveSheet_AsDataSet method for XLS file

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

III. For importing 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 Excel file using:
- ExcelDocument.easy_LoadXLSXFile method for XLSX file
- ExcelDocument.easy_LoadXLSBFile method for XLSB file
- ExcelDocument.easy_LoadXLSFile method for XLS file

Then, import the sheet data in GridView using ExcelDocument.easy_ReadExcelWorksheet_AsDataSet method.

Import range of Excel cells to GridView

EasyXLS enables you to import Excel data to GridView either from the entire sheet or from a range of cells. Importing only a range of cells is a very useful option especially for large Excel files because it reduces the speed of the import process.

In order to import 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 importing Excel to DataSet have parameters that permit importing only ranges of cells.

Import XLSX, XLSB, XLSM and XLS files to GridView

This code sample shows how to import XLSX file to GridView. Similarly, you can import XLSM, XLSB, XLSX files to GridView 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
- ExcelDocument.easy_ReadXLSActiveSheet_AsDataSet or ExcelDocument.easy_ReadXLSSheet_AsDataSet method for XLS files

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
ASP.NET Excel Library
full .NET version to import, export or convert Excel files
ASP.NET Excel Reader
.NET version to read and import Excel files
Download EasyXLS™ Excel Library for .NET

File formats:

MS Excel 97 - 2003
MS Excel 2007 - 2019
MS Excel 2021
Office 365
XLSXXLSMXLSBXLS
XMLHTMLCSVTXT