New to Telerik UI for ASP.NET MVC? Download free 30-day trial

Excel Export

The PivotGrid enables you to export its content to Excel.

By default, the Excel export is enabled when kendo.ooxml.min.js is loaded on the page. kendo.ooxml.min.js is included in kendo.all.min.js and kendo.web.min.js.

To initiate Excel export by using code, call the saveAsExcel method.

For more information, refer to the following resources:

Exporting the Content

By default, the PivotGrid exports the current data with the applied sorting and filtering functionalities. The PivotGrid does not export the current CSS theme in the Excel file. For more information on changing the visual appearance of the Excel document, refer to the following section on customization.

The dataCellTemplate, columnHeaderTemplate, and the rowHeaderTemplate options are not used during the export to Excel. For more information, refer to the following section on templates.

Customizing the Appearance

ExcelExport() allows the customization of the generated Excel document. The workbook event argument exposes the generated Excel workbook configuration. For more information on how the Excel documents work, refer to the article on Excel export in Kendo UI for jQuery.

To apply customizations during the export to Excel:

  1. Attach an Excel export handler.

        @(Html.Kendo().PivotConfigurator()
            .Name("configurator")
            .Filterable(true)
            .Events(e => e.ExcelExport("excelExport"))
            .Height(570)
        )
    
        <kendo-pivotgrid name="configurator"
                     filterable="true"
                     on-excel-export="excelExport"
                     height="570">
        </kendo-pivotgrid>
    
  2. In the handler, manipulate the generated workbook. The example alternates the background color of the rows cells.

    <script>
        function excelExport(e) {
            var sheet = e.workbook.sheets[0];
            for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
                if (rowIndex % 2 == 0) {
                    var row = sheet.rows[rowIndex];
                    for (var cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
                        row.cells[cellIndex].background = "#aabbcc";
                    }
                }
            }
        }
    </script>
    

Using Templates

The PivotGrid does not use dataCellTemplate, columnHeaderTemplate, and rowHeaderTemplate during Excel export and exports only its data because the templates may contain arbitrary HTML which cannot be converted to Excel column values.

See Also

In this article