Problem with MVC and Export to Excel

  1. #1

    Problem with MVC and Export to Excel

    Hello guys, I'm having an issue exporting a gridpanel data to an excel document.

    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
  2. #2
    Hi,

    I'm trouble to sort it out without a sample code reproducing the issue.
    Could you provide a simplified .aspx page that I can run without any change?
  3. #3

    Please Marked as solved

    Hello Daniil, thank you very much for responding to my issue. Thankfully i was able to resolve it by using the information found on this blog: http://blog.maartenballiauw.be/post/...ionResult.aspx

    In my case I had to override the ActionResult handler to render an Excel file instead of an ASP.Net page

    You can mark this post as solved

    Thank you,
    Rey
    Miami Web Design
  4. #4

    Need more help....am a beginner

    Hi Rey,

    I have the similar issue...and tried out the sample given in the URL http://blog.maartenballiauw.be/post/...ionResult.aspx

    But am not getting the result. I dont know how to override the ActionResult handler as you said....Can you give me the exact code for that?


    Thank you,
    Sara

Similar Threads

  1. Export to Excel
    By JonC in forum 1.x Help
    Replies: 9
    Last Post: Nov 13, 2012, 4:59 AM
  2. Export to Excel
    By ChrisO in forum 2.x Help
    Replies: 1
    Last Post: Jun 21, 2012, 4:08 PM
  3. problem in export to excel
    By danilo in forum 1.x Help
    Replies: 0
    Last Post: Nov 16, 2010, 3:07 PM
  4. Replies: 3
    Last Post: Mar 16, 2010, 1:50 PM
  5. Excel export problem
    By Nagaraj K Hebbar in forum 1.x Help
    Replies: 3
    Last Post: Aug 18, 2009, 5:36 PM

Tags for this Thread

Posting Permissions