Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-03-29
4
Medium Priority
?
277 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

610 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