?
Solved

Transfer System.Windows.Forms.DataGrid contents to MS Excel

Posted on 2007-03-29
4
Medium Priority
?
275 Views
Last Modified: 2008-03-17
Hi,

I have created my own sligtly customised grid. It inherits from System.Windows.Forms.DataGrid . I know the changes I have made change it from what the System.Windows.Forms.DataGrid but my changes are nto that dastic.

However, the key part to this question is - how can I easily and efficiently tranfer the contents of all my grid (assue if you like that it is a System.Windows.Forms.DataGrid object) to MS Excell (2002)

Hope You can help

BTW I'm using .Net 1.1 to create my winform app

Thanks

0
Comment
Question by:bowemc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
SystemExpert earned 1500 total points
ID: 18821707
Hi,
the following link has complete flow of code to export the datagrid data to Excel

http://www.dotnetjohn.com/articles.aspx?articleid=78

this link has details that what can be the problem whem you export data to excel

http://geekswithblogs.net/azamsharp/archive/2005/08/14/50166.aspx

Thanks & Regards
0
 
LVL 10

Expert Comment

by:SystemExpert
ID: 18821723
see this also

private void ExportLinkButton_Click(object sender, System.EventArgs e)
{
  string strTitle = “put the grid title here”;
  new DataGridExcelExporter(this.YourGridName , this.Page).Export(strTitle);
}
where,

strTitle is the title of the DataGrid.
DataGridExcelExporter is the name of main class.
this.YourGridName is the DataGrid object.
this.Page is the current Page object.

ref link : http://www.codeproject.com/csharp/export2excel.asp
0
 

Author Comment

by:bowemc
ID: 18823501
Hi

I'm trying to use the below code from http://www.codeproject.com/office/export.asp
 to export .

What reference do i need to add to use the excel stuff?

THANKS




                  Excel.ApplicationClass excel = new ApplicationClass();

                  excel.Application.Workbooks.Add(true);
                  DataTable table = (Dataset)grid;
                  int ColumnIndex=0;
                  foreach(Datacolumn col in table.Columns)
                  {  
                        ColumnIndex++;
                        excel.Cells[1,ColumnIndex]=col.ColumnName;
                  }
                  int rowIndex=0;
                  foreach(DataRow row in table.Row)
                  {        
                        rowIndex++;      
                        ColumnIndex=0;        
                        foreach(DataColumn col in table.Columns)        
                        {  
                              ColumnIndex++;                
                              excel.Cells[rowIndex+1,ColumnIndex]=row.Cells[col.ColumnName].Text;        
                        }
                  }
                  excel.Visible = true;
                  Worksheet worksheet = (Worksheet)excel.ActiveSheet;
                  worksheet.Activate();
0
 

Author Comment

by:bowemc
ID: 18823596
Also - I've noticed my dataset has more information than what my grid displays. THe grid is configurable so I only show my user what they want. Hense I only want to export what is in the actual grid compared to what is in the DataSet.

THANKS
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question