This is a migrated thread and some comments may be shown as answers.
Export to Excel
1 Answer 12 Views
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 09 Mar 2011, 12:06 AM
Hi all,

I am wanting to utilise the export to excel functionality of the rad grid, without actually displaying a grid.
Can this all be done in memory, without actually physically having a control on a page? The reason being,
the data i am displaying (summarised) and the data i want to export are very different.

There are some basic ways of exporting to excel for sure, but i figure leveraging the rad grid implementation will be more robust than something i can cobble together in a couple of hours.

Is what i am thinking even possible?

I would welcome any insight?

As a starting point, i was kind of thinking along the line of the code below.

//definately incomplete!!!
public void btnExport(object sender, eventargs e)
{

     RadGrid grid = new RadGrid();

     grid.AutoGenerateColumns = true;

     grid.ExportSettings.ExportOnlyData = true;
     grid.ExportSettings.IgnorePaging = true;

    grid.ExportSettings.OpenInNewWindow = true;
    grid.DataSource = myCollection;

     grid.DataBind();

     grid.MasterTableView.ExportToExcel();
}


Or am i just over complicating this?!

Thanks.

  

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 09 Mar 2011, 02:22 PM
Hello Adam,

This is the correct approach, however you will have to add RadGrid to the Controls collection of the Page before exporting.
RadGrid grid = new RadGrid();
Page.Controls.Add(grid);
grid.AutoGenerateColumns = true;
 
grid.ExportSettings.ExportOnlyData = true;
grid.ExportSettings.IgnorePaging = true;
 
grid.ExportSettings.OpenInNewWindow = true;
grid.DataSource = new string[] { "Adam", "John", "Michael", "Peter", "Brandon" };
 
grid.DataBind();
 
grid.MasterTableView.ExportToExcel();

Note that the response will be redirected to the file and the actual page in your browser won't be changed.

Best regards,
Daniel
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or