Read Excel using Dotnet application

steps:

1) create simple dotnet application(here i am used C#.net)

2) put the below code

//add namespace
using System.Data.OleDb;
//read Excel File
string FilePath =”c:\test.xls”;
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ FilePath +";Extended Properties=Excel 8.0");
OleDbDataAdapter da = new OleDbDataAdapter("select * from [sheet1$]", con);
DataTable dt = new DataTable();
//get data in datatable
da.Fill(dt);
Thnx
 

2 responses to “Read Excel using Dotnet application”

  1. alpesh Avatar
    alpesh

    i faced here some problem Like : –

    External table is not in the expected format

    actually my req. is system generate xls file n then user will update some col.

    then again nedd to import in DB .. at that time i face above error : External table is not in the expected format.

    i hope u will reply for suggestion…

  2. kricksen Avatar

    thanks for providing the simple example for reading excel files

Leave a Reply

Discover more from The Engineering Behind Enterprise AI

Subscribe now to keep reading and get access to the full archive.

Continue reading