Click here to Skip to main content
16,012,198 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
How to Import Excel file into C# in Windows form application.

Regards
Balamurugan
Posted
Updated 25-Nov-12 16:23pm
v2

 
Share this answer
 
Comments
Balamurugan1989 25-Nov-12 22:24pm    
I have updated my question...
For Viewing the content of the excel file which we uploaded for tis we should follow the below code:
{
OleDbConnection theConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=books.xls;Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\"");
theConnection.Open();
OleDbDataAdapter theDataAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", theConnection);
DataSet theDS = new DataSet();
DataTable dt = new DataTable();
theDataAdapter.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView;
}

For uploading a Excel file into C# windows application form we should follow the below code:
{
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Select file to be upload";
fDialog.Filter = "(*.xls)|*.xls";
if (fDialog.ShowDialog() == DialogResult.OK)
{
txtFileName.Text = fDialog.FileName.ToString();
}
 
Share this answer
 
Comments
Member 10345822 27-Jan-14 3:07am    
thanks Sir
Hi this is really a good solution have a look of this solution also

http://www.dotnetpools.com/2012/11/how-to-read-ms-excel-file-and-populate.html[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900