[CLOSED] Export to Excel - MVC

  1. #1

    [CLOSED] Export to Excel - MVC

    I have been trying to combine the following examples without success:

    Exporting a grid as a file from:
    http://mvc.ext.net/#/GridPanel_Pagin...Sorting/Local/

    and the excel format export from:
    https://examples2.ext.net/#/GridPane...ort_Data_Ajax/

    Can you please tell me how to add Excel file formatting:

                        
                        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.xsl"));
                        xtExcel.Transform(xml, null, Response.OutputStream);
    to the MVC action method:
             public ActionResult Submit(SubmitHandler handler)
            {
                return this.File(new System.Text.UTF8Encoding().GetBytes(handler.Xml.OuterXml), "application/xml", "submittedData.xml");
            }
    Last edited by Daniil; Aug 05, 2014 at 12:57 PM. Reason: [CLOSED]
  2. #2
  3. #3
    This does not work well.

    If you take the GridPanel_ArrayGrid/Remote_Load from your MVC examples download solution and add the following to the Remote_LoadController:

            public ActionResult ExportExcel(string data)
            {
                var xt = new XslCompiledTransform();
                var submitData = new Ext.Net.SubmitHandler(data);
                XmlNode xml = submitData.Xml;
    
                var s = new StringBuilder();
                var settings = new XmlWriterSettings()
                {
                    ConformanceLevel = ConformanceLevel.Auto
                };
    
                FileContentResult result = null;
                xt.Load(Server.MapPath("~/Resources/Excel.xsl"));
                System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(s, settings);
                xt.Transform(xml, writer);
                result = new FileContentResult(Encoding.UTF8.GetBytes(s.ToString()), "application/vnd.ms-excel");
                result.FileDownloadName = "Temp.xls";
    
                return result;
            }
        }
    And you add this in the script tag:

            var exportExcel = function () {
                debugger;
                Ext.net.DirectMethod.request({
                    url: "/Remote_Load/ExportExcel",
                    cleanRequest: true,
                    isUpload: true,
                    params: {
                        data: App.GridPanel1.getRowsValues()
                    }
                });
            };
    and add this to the Gird:

                .BottomBar(Html.X().PagingToolbar()
                    .DisplayInfo(false)
                    .Items(
                       Html.X().Button().Text("Export Excel").Handler("exportExcel();")
                    )
                )

    Opening the file first gives an Error saying that the format and the extension of the file do not match, and when you open the file you see all the data in the same line with no spaces or any kind of separator.
  4. #4
    Opening the file first gives an Error saying that the format and the extension of the file do not match, and when you open the file you see all the data in the same line with no spaces or any kind of separator.
    I guess that your XSLT file generates wrong excel file, please check it

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. Excel Export
    By maephisto in forum 1.x Help
    Replies: 1
    Last Post: May 13, 2011, 11:47 AM
  4. vb example of export to Excel
    By grosenbrock in forum 1.x Help
    Replies: 2
    Last Post: Aug 27, 2010, 6:22 PM
  5. [CLOSED] Excel export
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 24, 2009, 5:35 AM

Posting Permissions