Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i am working on excel sheet. i had already export data from a datagridview into excel sheet. now i want to view this excel sheet on click of a button. how could i do that.
thanx in advance
neaS
Posted

Good morning,

The link below shows how to automate Excel...
http://support.microsoft.com/kb/301982[^]

If you're looking to open a saved file, then try the following:

http://msdn.microsoft.com/en-us/library/h6ak8zt5.aspx
 
Share this answer
 
v2
Comments
BobJanova 31-Aug-11 11:30am    
5 from me, though I added some details in my answer.
Use Process.Start (as linked by Bert). Make sure you set UseShellExecute to true so that you can use Process.Start on the .xls. This will start whatever application you have associated with .xls (probably Excel, but it might not be) and load the sheet into it.
 
Share this answer
 
Hi,
suppose you have an excel sheet contains data in the following format


<br />
ID	ISBN	        Date<br />
1	0273600796	10/1/2011<br />
2	0071162070	10/1/2011<br />
3	0071162070	10/15/2011<br />
4	0070522235	10/15/2011<br />
5	0070527105	11/1/2011<br />
6	0070577277	11/1/2011<br />
7	007024801x	11/15/2011<br />
8	0071164278	12/1/2011<br />
9	0071140654	12/1/2011<br />



saved in excel file named "OutOfPrint.xls"
you can use the following code snip to read this file into datagridview



C#
DbProviderFactory factory =
                DbProviderFactories.GetFactory("System.Data.OleDb");

                using (DbConnection connection = factory.CreateConnection())
                {
                    connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
                Data Source=OutOfPrint.xlsx;Extended Properties=
                ""Excel 8.0;HDR=YES;""";

                    using (DbCommand command = connection.CreateCommand())
                    {
                        command.CommandText = "SELECT ID,ISBN,Date FROM [OutofPrint$]";

                        connection.Open();

                        using (DbDataReader dr = command.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                gvOutofPrint.Rows.Add(dr["ID"], dr["ISBN"],dr["Date"]);
                            }
                        }
                    }
                }


good luck
 
Share this answer
 
v3

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