.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

how can read .xls file in windows application using C#?

Posted By: Sagar Pardeshi     Posted Date: February 03, 2010    Points:2   Category :Windows Application

I have create windows application.Please tell me how can read value from .xls file in window application.

Author: Akhil Raj       [Moderator]      
Posted Date: February 03, 2010     Points: 5   
Author: Lalij Mer             
Posted Date: February 04, 2010     Points: 5   

try this code sample

using System.Data.OleDb;

private void btnRead_Click(object sender, EventArgs e)
string connStr = connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\Courier.xls;Extended Properties=ImportMixedTypes=Text;Excel 8.0;HDR=Yes;IMEX=1;";

//You must use the $ after the object you reference in the spreadsheet
OleDbDataAdapter adap = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connStr);

DataSet ds = new DataSet();
adap.Fill(ds, "Courier");
dataGridView1.DataSource = ds.Tables["Courier"].DefaultView;

catch (Exception ex)

Please Check my answer if you help....
Thank You...

Author: Jack Baker             
Posted Date: October 08, 2010     Points: 5   

Hi Sagar Pardeshi,

Excel Reader .NET can read XLS files. Include this .NET component to your project and you will be able to get xls file data for inserting it into the Database.

Here is the code of Excel Reader usage for .NET:
Dim Wbook = New DTG.Spreadsheet.Workbook   
Dim WSheet = Wbook.Worksheets(0)
Dim CELL A5 = WSheet.Cells("A5")
String s = A5.Value

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend