This is a migrated thread and some comments may be shown as answers.

Export to Excel using MVC

1 Answer 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erwin
Top achievements
Rank 1
Erwin asked on 30 Apr 2010, 03:54 PM
Hi,

I'm trying to use the Export to Excel functionality, provided by the RadGrid, in conjunction with the MVC framework. (Please ignore this thread if already asked, but every thread pops up when searching for MVC due to the menu bar).

Since it's MVC, the grid is only known by the view. I've tried something in the line of:
<
grdReport.DataSource = ViewData["Report"]; 
grdReport.DataBind(); 
grdReport.ExportSettings.ExportOnlyData = false
grdReport.ExportSettings.IgnorePaging = true
grdReport.ExportSettings.OpenInNewWindow = true
grdReport.MasterTableView.ExportToExcel(); 
%> 

But it only displays the grid, not exporting it. My guess is that at this point, the view is already being rendered, being it too late to change the headers, etc...

Is there a preferred way to export to Excel using MVC? If not, is there a way to export strictly programmatically and catch the export stream, instead of streaming it directly to the response?

Kind regards,
Dries

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 06 May 2010, 10:57 AM
Hello Dries,

I recommend you one of the following options:

1) Wrap your RadGrid together with a standard button within a form with runat="server" and then put your code in the click handler of this button.

2) Use the NPOI library as demonstrated in this KB article:
Exporting Grid data to Excel

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Erwin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or