C# Read Excel File Into DataTable – C# Programming Example
General

C# Read Excel File Into DataTable

In this example, we will fill some data into a datatable from excel application.
We created this DataTable example using with COM Object ( C# Read Excel File into DataTable without OleDb)

Berfore the creating codes, here is the examples screenshot

 

C# read Excel file

Step 1: For importing Excel to DataTable with Interop ,we have to  references Excel namespace to the project.

 

Step 2: Given this the using alias of Excel.

 

Step 3: Creating COM object referances and DataTable

Step 4: … and checking Excel program is exists

Step 5: Creating book, pages and range  variables

Step 6: Calculating rows and cols.

Converting Excel to DataTable in C#

Step 6: Define DataTable name and column names

 

Step 7: Reading step by step cols and rows into DataTable.

Step 8: Reading data from DataTable

Step 9: After reading, relase the excel project.

 

Here are the all codes:

 

Sources: I used to this articles for reading excel file and filling into datatable

Reading Excel file in C# Console Application

C# DataTable Examples

 

1 Comment

  • I’m very impressed with the way you explained all the code. Hope you can keep sharing information like this in the future. I’m starting with C# and I’m overwhelmed with the libraries part of the code.

    Unfortunately the Microsoft Excel 15.0 Object Library is not available. I do have a office 16.0 Object Library. I Added it, but I keep having errors related with the excelApp namespace.

    What is wrong?
    Thank you.
    TJ

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: