Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
kindly help how do i open a excel sheet on clicking a button.and for connection string why we are providing like this explain me about the connection string "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 8.0;HDR=YES;\"
Posted
Updated 15-Apr-14 9:12am
v2
Comments
Ganesh KP 15-Apr-14 2:53am    
Where you want to read the excel file? You have given two questions, how to read and how to open? Which is your question? Please give some clarity regarding your question.
karthikeyan9966 15-Apr-14 3:01am    
how to open an excel file on clicking a button
gggustafson 15-Apr-14 12:00pm    
Do you want to get to the contents of the Excel file or do you want Excel to open the file for you (i.e., open the file in a new window)?
Bh@gyesh 15-Apr-14 5:23am    
Hi,
Is it your window application or web application?
Try : Process.Start(pathoffile);
ZurdoDev 15-Apr-14 15:11pm    
What do you mean by open? I know it makes sense in your head but you can open it in code and process it all in code so the user never sees anything. Or, you can open it for the user. You need to give more info.

1 solution

if u r looking for importing data from excel file and show it to datagridview /save to database then u may try


DialogResult dr= openFileDialog.ShowDialog();
          if (dr == DialogResult.OK && openFileDialog.CheckFileExists )
          {
              string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", openFileDialog.FileName);
              string query = String.Format("select * from [{0}$]", "Sheet1");
              OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
              DataSet dataSet = new DataSet();
              dataAdapter.Fill(dataSet);
              dgvStudents.DataSource = dataSet.Tables[0];
          }
 
Share this answer
 

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