This is a migrated thread and some comments may be shown as answers.

Export Excel Error

3 Answers 97 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 30 Jul 2018, 04:37 PM

Hi everyone, I'm new in Kendo ASP.NET and I would like to see if some one could help me or give me an a guide. Rigth now I'm trying to implement an excel export of a pivotGrid. I already set all the pivotgrid configuration as in Razor as in the controller but when ran it I got the error (ScreenShot Attached).

The following is the configuration of the pivotGrid the View and Controller.

 

View:

@ModelType IEnumerable(Of TelerikMvcVB.HomeModel)

<link href="@Url.Content("~/Content/bootstrap.css")" rel="stylesheet" type="text/css" />

@* Content-box fixes as per http://docs.telerik.com/kendo-ui/third-party/using-kendo-with-twitter-bootstrap article  *@
<link href="@Url.Content("~/Content/box-sizing-fixes.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

<link href="https://kendo.cdn.telerik.com/2018.2.620/styles/kendo.common-bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="https://kendo.cdn.telerik.com/2018.2.620/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
<link href="https://kendo.cdn.telerik.com/2018.2.620/styles/kendo.bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://kendo.cdn.telerik.com/2018.2.620/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.2.620/js/jszip.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.2.620/js/kendo.all.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.2.620/js/kendo.aspnetmvc.min.js"></script>
<script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script>
<script src="~/Scripts/kendo/jszip.min.js"></script>


<div>
    <div style="margin-top:-2%">
        <h2>Kendo PivotGrid - Razor</h2>
    </div>
    <button id="export" class="k-button k-button-icontext hidden-on-narrow"><span class="k-icon k-i-excel"></span>Exportar Excel</button>
    <div class="responsive-message"></div>

    <div>
        @(Html.Kendo().PivotConfigurator().Name("configurator") _
                    .HtmlAttributes(New With {.class = "hidden-on-narrow"}) _
                    .Filterable(True) _
                    .Sortable() _
                    .Height(570)
        )

        @(Html.Kendo().PivotGrid(Of HomeModel)() _
                            .Name("pivotgrid") _
                            .Excel(Function(excel) excel _
                                .FileName("PruebaExcelRazor.xlsx") _
                                .ForceProxy(Url.Action("Excel_Export_Save", "Home"))) _
                            .HtmlAttributes(New With {.class = "hidden-on-narrow"}) _
                            .Sortable() _
                            .Configurator("#configurator") _
                            .ColumnWidth(120) _
                            .Height(570) _
                            .BindTo(Model) _
                            .DataSource(Function(dataSource) dataSource _
                                .Ajax() _
                                .Schema(Function(schema) schema _
                                .Cube(Function(cube) cube _
                                    .Dimensions(Function(dimensions) _
                                    {
                                        dimensions.Add(Function(model) model._nombre).Caption("Nombre"),
                                        dimensions.Add(Function(model) model._idProductos).Caption("Id Producto"),
                                        dimensions.Add(Function(model) model._precio).Caption("Precio"),
                                        dimensions.Add(Function(model) model._cantidad).Caption("Cantidad")
                                    }) _
                                    .Measures(Function(measures) measures.Add("Contar Productos").Field(Function(model) model._idProducto).AggregateName("Count"))
                            ))))

        )

    </div>
</div>

@Scripts.Render("~/bundles/bootstrap")
@*@RenderSection("scripts", required:=False)*@

<style>
    #pivotgrid {
        display: inline-block;
        vertical-align: top;
        width: 70%;
    }

    #configurator {
        display: inline-block;
        vertical-align: top;
    }

    .hidden-on-narrow {
        display: inline-block;
        vertical-align: top;
    }
</style>

<script>
    $(function () {
        $("#export").click(function () {
            $("#pivotgrid").getKendoPivotGrid().saveAsExcel();
        });
    });

    function onError(e) {
        alert("error: " + kendo.stringify(e.errors[0]));
    }
</script>

 

Controller:

Imports System.Runtime.InteropServices
Imports System.Web
Imports Kendo.Mvc.Extensions
Imports Kendo.Mvc.UI


Public Class HomeController
    Inherits System.Web.Mvc.Controller

    Function Index() As ActionResult
        Dim DA As New DataAccess
        Dim lstProductos = DA.GetProductList()
        Return PartialView("~/Views/Home/Index.vbhtml", lstProductos)
    End Function

    <HttpGet>
    Function Excel_Export() As ActionResult
        Return View()
    End Function


    <HttpPost>
    Function Excel_Export_Save(ByVal contentType As String, ByVal base64 As String, ByVal fileName As String) As ActionResult
        Try
            Dim fileContents = Convert.FromBase64String(base64)
            Return File(fileContents, contentType, fileName)
        Catch ex As Exception

        End Try
    End Function


    Function ListGetData() As ActionResult
        Try
            Dim DA As New DataAccess
            Dim lstProductos = DA.GetProductList()
            Return View("~/Views/Home/Index.vbhtml", lstProductos)
            'Return lstProductos
        Catch ex As Exception
            ' Return HttpStatusCodeResult(400, "")
        End Try
    End Function
End Class

Thanks for any help about the error..I made the code from the example of the web page from the remote binding

 

 

 

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 01 Aug 2018, 01:01 PM
Hello,

The problem here is that the ForceProxy method of the Kendo UI PivotGrid for ASP.NET MVC accepts boolean value as parameter. Currently the passed parameter is string indicating the proxy url. I guess you want to specifiy the proxy url and then ProxyURL method should be used just like the  PivotGrid / Export to Excel demo. 
 


Regards,
Boyan Dimitrov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Victor
Top achievements
Rank 1
answered on 03 Aug 2018, 03:27 PM

Hi Boyan Dimitrov

Thanks for your answer and help, just I've a doubt, I'm not pretty sure what do you mean when you said "Currently the passed parameter is string indicating the proxy url" as you can see I'm using the same structure for the ProxyURL and the methods of the controller side as the example of the page. In which method is passing a string as parameter?. Again thanks for your help, I.m really new in  Kendo UI PivotGrid for ASP.NET MVC, and I didn't get about this string parameter that you're saying

0
Boyan Dimitrov
Telerik team
answered on 07 Aug 2018, 10:19 AM
Hello,

The code on the controller side is just fine. I meant that the configuration code for the Kendo UI PivotGrid for ASP.NET MVC: 

@(Html.Kendo().PivotGrid(Of HomeModel)() _
                           .Name("pivotgrid") _
                           .Excel(Function(excel) excel _
                               .FileName("PruebaExcelRazor.xlsx") _
                               .ForceProxy(Url.Action("Excel_Export_Save", "Home"))) _

ForceProxy and ProxyUrl are different methods. ForceProxy method forces the use of server-side proxy even if browser local saving is supported and it accepts boolean parameter to indicate whether to force it or not. In the code above ForceProxy method is called and Url.Action("Excel_Export_Save", "Home") parameter is passed (which is string, but the method expects bool value). I think that you want to use ProxyUrl which accepts string parameter. So the code should look like: 

@(Html.Kendo().PivotGrid(Of HomeModel)() _
                           .Name("pivotgrid") _
                           .Excel(Function(excel) excel _
                               .FileName("PruebaExcelRazor.xlsx") _
                               .ProxyURL(Url.Action("Excel_Export_Save", "Home"))) _


Regards,
Boyan Dimitrov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PivotGrid
Asked by
Victor
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Victor
Top achievements
Rank 1
Share this question
or