[CLOSED] [1.0] MVC Grid/Store Export to .xls/.csv/.xml Error

Page 2 of 4 FirstFirst 1234 LastLast
  1. #11
    Vlad,

    My action code is:

    
    public ActionResult Write(string data, string format)
    {
        Ext.Net.SubmitHandler submitData = new Ext.Net.SubmitHandler(data);
        XmlNode xml = submitData.Xml;
    
        MemoryStream m = new MemoryStream(System.Text.Encoding.Default.GetBytes(xml.OuterXml));
    
        XPathDocument xpathDoc = new XPathDocument(new StreamReader(m));
    
        XslCompiledTransform transform = new XslCompiledTransform();
    
        StringBuilder resultString = new StringBuilder();
    
        XmlWriter writer = XmlWriter.Create(resultString);
    
        transform.Load(Server.MapPath("~/Content/Excel.xsl"));
    
        transform.Transform(xpathDoc, writer);
    
        var result = new FileContentResult(System.Text.Encoding.Default.GetBytes(resultString.ToString()), "application/vnd.ms-excel");
        result.FileDownloadName = "Test.xls";
    
        return result;
    }
    At the moment I am only working with transforms to excel but once this is working, would then modify it to work with all three types.
  2. #12
    Hi,

    Do you have a html form? Form is required for IsUpload mode
    Please see the links which I mentioned in the following post
    http://forums.ext.net/showthread.php...ll=1#post42321
    Vladimir Shcheglov
    Sr. Developer
  3. #13
    Duh! I had changed my wrapping Panel to a FormPanel yesterday and then changed it back because I couldnt get it working and didn't want to mess about too much.

    Anyway, all is working fine now, thank you very much for the assistance :)
  4. #14

    Same issue as you are having. Still not resolved

    Quote Originally Posted by Vladimir View Post
    Hi,

    Do you have a html form? Form is required for IsUpload mode
    Please see the links which I mentioned in the following post
    http://forums.ext.net/showthread.php...ll=1#post42321

    Hello,

    I have this in my View page :

       <ext:Button ID="Button40" runat="server" Text="To Excel" Icon="PageExcel">
                            <DirectEvents>
                            <Click Url="/Data/ExcelDownload" IsUpload="true" Method="POST">
                            <ExtraParams>
                                <ext:Parameter Name="data" Value="#{GridPanel1}.getRowsValues()" Mode="Raw" Encode="true" />
                                <ext:Parameter Name="format" Value="xls" Mode="Value" />
                            </ExtraParams>
                            </Click>
                            </DirectEvents>
    This is within the GridPanel.

    Also , as Vlad had written, I have written the same code.

     public ActionResult ExcelDownload(string data, string format)
            {
                Ext.Net.SubmitHandler submitData = new Ext.Net.SubmitHandler(data);
                XmlNode xml = submitData.Xml;
    
                MemoryStream m = new MemoryStream(System.Text.Encoding.Default.GetBytes(xml.OuterXml));
    
                XPathDocument xpathDoc = new XPathDocument(new StreamReader(m));
    
                XslCompiledTransform transform = new XslCompiledTransform();
    
                StringBuilder resultString = new StringBuilder();
    
                XmlWriter writer = XmlWriter.Create(resultString);
    
                transform.Load(Server.MapPath("../../web references/webreference/Excel.xsl"));
    
                transform.Transform(xpathDoc, writer);
    
                var result = new FileContentResult(System.Text.Encoding.Default.GetBytes(resultString.ToString()), "application/vnd.ms-excel");
                result.FileDownloadName = "Test.xls";
    
                return result;
            }
    But on click of Excel button, I am getting the error as described in the attached screenshot.

    Please advice asap. I am stuck up because of this.

    Regards
    Attached Thumbnails badresponseerror.jpg  
    Last edited by vbdotnetphp; Feb 05, 2014 at 2:35 PM.
  5. #15
    Hi @vbdotnetphp,

    Please wrap the code in [CODE] tags. Please do not re-post, just edit the existing post.
    Forum Guidelines For Posting New Topics
    More Information Required
  6. #16
    Thank you.

    Could you, please, provide a full test case to reproduce?
  7. #17

    OutputStream is not available when a custom TextWriter is used

    Quote Originally Posted by Daniil View Post
    Thank you.

    Could you, please, provide a full test case to reproduce?
    Hi Daniil.

    Thanks. But I figured this one out.
    Actually I was passing the wrong URL.

    It works now.

    But one thing, it is pulling up only the current page of the datagrid.
    Is it possible to export all the rows from the datagrid?

    Please advice.
  8. #18
    Probably, you are using remote paging. It means that a Store/GridPanel has records for the current page only. If you you want all the data to be exported, you should get it on server accessing directly the data store (a database or else)
  9. #19

    OutputStream is not available when a custom TextWriter is used

    Quote Originally Posted by Daniil View Post
    Probably, you are using remote paging. It means that a Store/GridPanel has records for the current page only. If you you want all the data to be exported, you should get it on server accessing directly the data store (a database or else)
    Hi Daniil,

    Thanks again.

    I did that and it worked.
    But now the issue is, I am not able to open the downloaded excel file.

    Please check the attached screenshot for the same.

    My controller code is as follows :

     
    public ActionResult ExcelDownload()
            {
    
                string _data = Convert.ToString(Session["memberqry"]);//this entire data is stored in a session and got in the string variable
                Ext.Net.SubmitHandler submitData = new Ext.Net.SubmitHandler(_data);
                XmlNode xml = submitData.Xml;
    
                MemoryStream m = new MemoryStream(System.Text.Encoding.Default.GetBytes(xml.OuterXml));
    
                XPathDocument xpathDoc = new XPathDocument(new StreamReader(m));
    
                XslCompiledTransform transform = new XslCompiledTransform();
    
                StringBuilder resultString = new StringBuilder();
    
                XmlWriter writer = XmlWriter.Create(resultString);
    
    
                string _pth = Server.MapPath("~/web references/webreference/Excel.xsl");
                transform.Load(_pth);
    
                transform.Transform(xpathDoc, writer);
    
                var result = new FileContentResult(System.Text.Encoding.Default.GetBytes(resultString.ToString()), "application/vnd.ms-excel");
                result.FileDownloadName = "AccountDetails"+System.DateTime.Today.ToShortDateString()+"_"+System.DateTime.Now.ToShortTimeString()+".xls";
    
                return result;
            }
    And the data contains some 33131 rows in it. (It's in JSON format)


    Due to the attachment limit, I am not able to provide you the copy of data and the xls file.

    But,
    To see this live, you can do the following :

    1. Please go to url : http://test.pricingsociety.com/account/adminlogin
    2. Login with credentials : pricings/35Mitch35
    3. Click "Members" (first icon in the "Membership Management" section)
    4. Wait till the Members grid is populated
    5. Click the "To Excel" button.
    6. It will download
    7. Try to open this file. And you will see the error.



    Regards
    Attached Thumbnails excelsheetopeningissue.JPG  
  10. #20
    What is written in the .log file?
Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. [CLOSED] how to export few columns from grid store to excel?
    By rnachman in forum 1.x Premium Help
    Replies: 1
    Last Post: Mar 28, 2012, 8:32 PM
  2. [CLOSED] MVC Grid/Store Export to .xls/.csv/.xml
    By softmachine2011 in forum 1.x Premium Help
    Replies: 9
    Last Post: Jun 17, 2011, 1:16 PM
  3. [CLOSED] Export dynamically created Grid/Store
    By CarWise in forum 1.x Premium Help
    Replies: 1
    Last Post: May 05, 2011, 12:40 PM
  4. Replies: 1
    Last Post: Apr 19, 2010, 2:44 PM
  5. [CLOSED] Error 500 saving grid store
    By harafeh in forum 1.x Premium Help
    Replies: 4
    Last Post: Jun 30, 2009, 2:59 PM

Posting Permissions