We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Export to Excel from web service

Hi.
I want to export data from a grid to Excel using a web service.
I have the following code in aspx:


            $(function () {
                                $("#Grid1").ejGrid({
                                    Locale: "es-ES",
                                    allowPaging: true,
                                    allowSorting: true,
                                    allowGrouping: true,
                                    groupSettings: { groupedColumns: ["empresa"] },
                                    toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.ExcelExport] },
                                    columns: [
                                    { field: "empresa", headerText: "Empresa", width: 275, textAlign: ej.TextAlign.Left }
                                    ],
                                    toolbarClick: function (e) {
                                        this.exportGrid = this["export"];
                                        if (e.itemName == "exportación Excel") {
                                            this.exportGrid('WebService.asmx/ExcelExport');
                                            e.cancel = true;
                                        }
                                    }


                                });
                            })



And in the file WebService.asmx I have this code:

    <System.Web.Http.ActionName("ExcelExport")>
    <AcceptVerbs("POST")>
    Public Sub ExcelExport(gridMode As String)
        Dim gridModel1 As String = HttpContext.Current.Request.Params("GridModel")
        Dim gridProperty As GridProperties = ConvertGridObject(gridModel)
        Dim exp As New ExcelExport()
        Dim result As IEnumerable(Of Order) = db.Orders.ToList()
        exp.Export(gridProperty, result, "Export.xlsx", ExcelVersion.Excel2010, False, False, "flat-saffron")
    End Sub



But it does not work.
How do I have to make it work for export?

The Grid is in a modal div, but I've tried a div with no modal and it does not work for me either.

Thanks.














3 Replies

RU Ragavee U S Syncfusion Team December 23, 2016 12:02 PM UTC

Hi Juan, 

We have created a grid exporting sample with webservices, which can be downloaded from the below location.

Sample Linkhttp://www.syncfusion.com/downloads/support/directtrac/general/ze/JS_Export1434829110 

We would like you to ensure the below cases in your sample. 

1.       Please ensure the URL path mentioned within the export method of the ejGrid.  
2.       Also, in toolbarClick event of the Grid, you have checked the itemName as “exportación Excel”. Have you modified the the Toolbar item Name using the ej.Grid.Locale object? 
3.       Also, the locale property is incorrectly specified in your sample code as “Locale” instead of “locale”. 

Please try the above provided sample and if you still face any difficulties, please share following information. 

1.       Screenshot/Video demo of the issue that you are facing. 
2.       If script error/exception obtained while exporting, share the screenshot of the call stack of the exception. 
3.       If possible, please reproduce the issue in the above provided sample and share. 

Regards, 
Ragavee U S. 



JU Juan December 23, 2016 03:17 PM UTC

Thank you. I will check it...

Regards.


RU Ragavee U S Syncfusion Team December 27, 2016 06:34 AM UTC

Hi Juan, 

Please check the given sample and let us know whether it works for you. 

Regards, 
Ragavee U S. 


Loader.
Live Chat Icon For mobile
Up arrow icon