Solved

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

Posted on 2007-03-29
4
273 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 500 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

Independent Software Vendors: 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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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