Oct 05, 2010, 9:09 PM
Problem with MVC and Export to Excel
Hello guys, I'm having an issue exporting a gridpanel data to an excel document.
The Code:
The Error:
Colour Graphic Design
The Code:
string json = e.ExtraParams["GridData"].ToString();
StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
XmlNode xml = eSubmit.Xml;
this.Response.Clear();
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls");
XslCompiledTransform xtExcel = new XslCompiledTransform();
xtExcel.Load(Server.MapPath("Excel/XSLStyleSheet/Example2.xsl"));
xtExcel.Transform(xml, null, this.Response.OutputStream);
this.Response.End();
The Error:
Server Error in '/' Application.
--------------------------------------------------------------------------------
OutputStream is not available when a custom TextWriter is used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: OutputStream is not available when a custom TextWriter is used.
Source Error:
Line 85: XslCompiledTransform xtExcel = new XslCompiledTransform();
Line 86: xtExcel.Load(Server.MapPath("Excel/XSLStyleSheet/Example2.xsl"));
Line 87: xtExcel.Transform(xml, null, this.Response.OutputStream); <============== ERROR LINE
Line 88: this.Response.End();
Line 89: }
Colour Graphic Design