User GuideFAQHow to import Excel file in C# and VB.NET
How to import Excel file in C# and VB.NET
EasyXLS™ library allows you to import data from an Excel file or other sheet elements like cell formatting, charts, pivot tables, comments, images and others.
EasyXLS can be successfully used to also import large Excel files having big volume of data with fast importing time.
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
EasyXLS permits you to import Excel files without Excel installed, without Interop, without OLEDB or any other additional software installed.
Step 1: Download and install EasyXLS Excel Library for .NET
To download the trial version of EasyXLS Excel Library, press the below button:
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.
Step 4: Run C# or VB.NET code that imports data from Excel file
The below example shows how to import data from Excel file in C# and VB.NET. After that, best techniques about importing the entire Excel file structures or importing Excel data to DataTable, GridView, DataGridView, DataSet, DataGrid and List are shown.
1. Import data from Excel file
EasyXLS allows you to import data from an Excel sheet or from the active Excel sheet. The entire sheet data or only data from ranges of cells can be imported.
// Create an instance of the class that imports Excel files
ExcelDocument workbook = new ExcelDocument();
// Import Excel file
DataSet ds = workbook.easy_ReadXLSXActiveSheet_AsDataSet("C:\\Samples\\Excel file.xlsx");
' Create an instance of the class that imports Excel filesDim workbook As New ExcelDocument
' Import Excel fileDim ds As DataSet = workbook.easy_ReadXLSXActiveSheet_AsDataSet("C:\Samples\Excel file.xlsx")
EasyXLS enables you to import Excel data 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.
5. Import all Excel file structures
EasyXLS allows you to import the whole Excel file with sheets, data inside sheets, formulas, cell formatting, comments, hyperlinks, images, data validation, page setup, macros, groups, filters, charts, pivot tables and pivot charts.
// Create an instance of the class that imports Excel files
ExcelDocument workbook = new ExcelDocument();
// Import Excel filebool success = workbook.easy_LoadXLSXFile("C:\\Samples\\Excel file.xlsx");
' Create an instance of the class that imports Excel filesDim workbook As New ExcelDocument
' Import Excel fileDim success As Boolean = workbook.easy_LoadXLSXFile("C:\Samples\Excel file.xlsx")
6. Import Excel file to SQL table in C# and VB.NET
EasyXLS library can be used to import Excel data to database like SQL Server, MySQL, Oracle, MS Access or any other database.
7. Import Excel file to DataTable in C# and VB.NET
EasyXLS library can be used to import Excel sheets into DataTable. The DataTable can be the used as data source of a GridView, DataGridView, DataGrid or for any other purposes.