Read (Import) Excel File Without OLEDB, Microsoft Office or Interop Library in C# and
Read (Import) Excel File Without OLEDB, Microsoft Office or Interop Library in C# and
Net
Read (Import) Excel file without OLEDB, Microsoft Office or Interop Library in C# and VB.Net (/Articles/Read-Import-Excel-file-without-OLEDB-Mic
rosoft-Office-or-Interop-Library-in-C-and-VBNet.aspx)
01 Jun 2018
Mudassar Khan (/Authors/Mudassar-Khan.aspx)
1
Comments
54128 Views
Excel (/Categories/Excel.aspx) DataGridView (/Categories/DataGridView.aspx) Windows Forms (/Categories/Windows-Forms.aspx) DataTable (/Categories/DataTable.aspx) OpenXml (/Categories/OpenXml.aspx) ClosedXml
(/Categories/ClosedXml.aspx)
Here Mudassar Ahmed Khan has explained with an example, how to read (import) Excel file without using OLEDB or installing Microsoft Office Excel or Interop Library in C# and VB.Net.
The Excel file will be read using ClosedXml and OpenXml DLLs which does not require OLEDB and does not require Microsoft Office Excel or Interop Library software to be installed.
Download
In this article I will explain with an example, how to read (import) Excel file without using OLEDB or installing Microsoft Office Excel or Interop Library in C# and VB.Net.
The Excel file will be read using ClosedXml and OpenXml DLLs which does not require OLEDB and does not require Microsoft Office Excel or Interop Library software to be installed.
Download DocumentFormat.OpenXml and ClosedXml Libraries
You can download the libraries using the following download locations.
Note: The DLL files of both OpenXml and ClosedXml are present in the attached sample.
Form Controls
I have added a DataGridView and a Button to the Windows Form. I have also added an OpenFileDialog to the Form which allow us to select the excel file.
https://www.aspsnippets.com/Articles/Read-Import-Excel-file-without-OLEDB-Microsoft-Office-or-Interop-Library-in-C-and-VBNet.aspx 1/8
11/4/22, 22:58 Read (Import) Excel file without OLEDB, Microsoft Office or Interop Library in C# and VB.Net
Namespaces
C#
using System.IO;
using System.Data;
using ClosedXML.Excel;
VB.Net
Imports System.IO
Imports System.Data
Imports ClosedXML.Excel
Selecting the Excel File
When the Select File button is clicked, it shows the Open File Dialog, using which we need to select the Excel file we want to import to DataGridView control.
C#
https://www.aspsnippets.com/Articles/Read-Import-Excel-file-without-OLEDB-Microsoft-Office-or-Interop-Library-in-C-and-VBNet.aspx 2/8
11/4/22, 22:58 Read (Import) Excel file without OLEDB, Microsoft Office or Interop Library in C# and VB.Net
End Sub
Importing the Excel File’s Sheet to DataGridView control
When the Open Button is clicked, the following event handler is executed. First the path of the selected Excel file is read and then the Excel file is read using the ClosedXml WorkBook class object.
Then the instance of the first Sheet is determined and all the rows present in the Sheet are fetched.
Finally a loop is executed over the fetched rows and a DataTable is populated which is then used to populate the DataGridView.
C#
//
https://www.aspsnippets.com/Articles/Read-Import-Excel-file-without-OLEDB-Microsoft-Office-or-Interop-Library-in-C-and-VBNet.aspx 3/8
11/4/22, 22:58 Read (Import) Excel file without OLEDB, Microsoft Office or Interop Library in C# and VB.Net
https://www.aspsnippets.com/Articles/Read-Import-Excel-file-without-OLEDB-Microsoft-Office-or-Interop-Library-in-C-and-VBNet.aspx 4/8
11/4/22, 22:58 Read (Import) Excel file without OLEDB, Microsoft Office or Interop Library in C# and VB.Net
Screenshots
Excel File
D t G idVi ith E ld t
https://www.aspsnippets.com/Articles/Read-Import-Excel-file-without-OLEDB-Microsoft-Office-or-Interop-Library-in-C-and-VBNet.aspx 5/8
11/4/22, 22:58 Read (Import) Excel file without OLEDB, Microsoft Office or Interop Library in C# and VB.Net
Downloads
Download
Related Articles
Here Mudassar Ahmed Khan has provided solutions to the issue The OLE DB provider ampquotMicrosoft.Ace.OLEDB.12.0ampquot for linked server ampquot(null)ampquot reported
an error. Access denied. while
Comments
Gilberto Espejel
— Aug 09, 2021 10:08 PM 189.160.215.224
Amazing tutorial super fast to implement and exactly what I needed. Thank you so much.
Add Comments
https://www.aspsnippets.com/Articles/Read-Import-Excel-file-without-OLEDB-Microsoft-Office-or-Interop-Library-in-C-and-VBNet.aspx 6/8
11/4/22, 22:58 Read (Import) Excel file without OLEDB, Microsoft Office or Interop Library in C# and VB.Net
You can add your comment about this article using the form below. Make sure you provide a valid email address
else you won't be notified when the author replies to your comment
Please note that all comments are moderated and will be deleted if they are
Not relavant to the article
Spam
Advertising campaigns or links to other sites
Abusive content.
Name
Name
Comment
Comment
Security code:
Add Comment
Doug
Just want to thank you very much for this article. I have spent hours searching for a solution to a very similar page I am building and I was giving up hope on getting it to work.
https://www.aspsnippets.com/Articles/Read-Import-Excel-file-without-OLEDB-Microsoft-Office-or-Interop-Library-in-C-and-VBNet.aspx 7/8
11/4/22, 22:58 Read (Import) Excel file without OLEDB, Microsoft Office or Interop Library in C# and VB.Net
©
2022
www.aspsnippets.com (https://www.aspsnippets.com/)
All rights reserved | Privacy Policy (/PrivacyPolicy.aspx)
| Powered by Excelasoft Solutions (http://www.excelasoft.com/)
(https://www.facebook.com/pages/ASPSnippets/306994206006035)
(https://plus.google.com/110371172807820981480) (https://twitter.com/aspsnippets)
(/Rss.ashx)
https://www.aspsnippets.com/Articles/Read-Import-Excel-file-without-OLEDB-Microsoft-Office-or-Interop-Library-in-C-and-VBNet.aspx 8/8