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


Top 5 Contributors of the Month
Easy Web
Imran Ghani

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
Hi


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

Responses
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)
{
try
{
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)
{
MessageBox.Show(ex.Message);
}
}


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

Lalit.
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.
http://www.devtriogroup.com/ExcelReader

Here is the code of Excel Reader usage for .NET:
Dim Wbook = New DTG.Spreadsheet.Workbook   
Wbook.ReadXLS("ExcelReaderTest.xls")
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
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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