Edit this page

Excel Export

As of Kendo UI Q3 2014 (2014.3.1119) version, the Kendo UI Grid can export its data in the form of an Excel document.

Configuration

Enable Excel Export

To enable Excel export include the corresponding toolbar command and configure the export settings.

For more information on this issue, refer to this online demo.

The following example demonstrates how to enable the Excel export functionality.

Example
    <%: Html.Kendo().Grid<MvcApplication.Models.ProductViewModel>()
        .Name("grid")
        .ToolBar(tools => tools.Excel())
        .Excel(excel => excel
            .FileName("Products.xlsx")
        )
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("Products_Read", "Home"))
        )
    %>
    @(Html.Kendo().Grid<MvcApplication.Models.ProductViewModel>()
        .Name("grid")
        .ToolBar(tools => tools.Excel())
        .Excel(excel => excel
            .FileName("Products.xlsx")
        )
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("Products_Read", "Home"))
        )
    )

To initiate the Excel export through code, call the saveAsExcel method.

Important

Older browsers, such as Internet Explorer 9 and below and Safari, require the implementation of a server proxy.

Output the Result

Through its default configuration, the Kendo UI Grid exports the current page of the data with sorting, filtering, grouping, and aggregates applied. To export all pages, refer to this section.

The Grid uses the current column order, visibility, and dimensions to generate the Excel file. It 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 this section.

Important

  • The Grid exports only data-bound columns. Template and command columns are ignored.
  • The Format option is not used during export. For more information on this, refer to this section.
  • The ClientTemplate option is not used during export. For more information on this, refer to this section.
  • The DetailTemplate option is not used during export. For more information on this, refer to this section.

Common Scenarios

Export All Data

By default, the Kendo UI Grid exports only the current page of data. To export all pages, set the AllPages option to true.

Important

When the AllPages option is set to true the Grid makes a read request for all data. If the data items are too many, the browser may become unresponsive. Consider implementing server-side export for such cases.

The following example demonstrates how to export all the data.

Example
    <%: Html.Kendo().Grid<MvcApplication.Models.ProductViewModel>()
        .Name("grid")
        .ToolBar(tools => tools.Excel())
        .Excel(excel => excel
            .AllPages(true)
        )
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("Products_Read", "Home"))
        )
    )
    %>
    @(Html.Kendo().Grid<MvcApplication.Models.ProductViewModel>()
        .Name("grid")
        .ToolBar(tools => tools.Excel())
        .Excel(excel => excel
            .AllPages(true)
        )
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("Products_Read", "Home"))
        )
    )

Customize Excel Documents

The excelExport event 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 this article.

For more information on a possible approach to customize the generated Excel document, refer to this runnable how-to example.

Set the Column Templates

Kendo UI Grid does not use the ClientTemplate during Excel export. It exports only the data. The reason is that a column template may contain arbitrary HTML which cannot be converted to Excel column values.

For more information on how to use a column template that does not contain HTML, refer to this runnable how-to example.

Define the Column Format

The Kendo UI Grid does not use the Format option during Excel export because some Kendo UI formats are incompatible with Excel. To format the cell values, set the format option of the cells.

The page on creating a custom number format describes the formats supported by Excel.

For more information on how to format the cell values, refer to this runnable how-to example.

Use the Detail Template

The Kendo UI Grid does not export its DetailTemplate for the same reason it does not export the column templates. If the detail template contains another Grid, follow this runnable how-to example.

Export Multiple Grids

For more information on how to export multiple Grids to a separate Excel sheet in a single Excel document, refer to this runnable how-to example.

Use Server-Side Processing

To export huge datasets to Excel, a well-suited solution is the new RadSpreadStreamProcessing library which is part of the Telerik Document Processing (TDP) by Progress.

TDP handles the data import, export, and processing from the following formats:

  • Excel Microsoft Office Open XML Spreadsheet (.xlsx)
  • Comma-separated values (.csv)
  • Tab-separated values (.txt)
  • Portable document format (.pdf) (export only)

Important

The Telerik Document Processing libraries are distributed as part of the UI for ASP.NET MVC and are available for the Kendo UI Enterprise and DevCraft bundles.

For examples on how to export Excel files, refer to the example on the integration of the Document Processing Library and the Grid for ASP.NET MVC, or to the information on the RadSpreadProcessing library.

See Also

Other articles on the Kendo UI Grid for ASP.NET MVC:

Articles on Telerik UI for ASP.NET MVC: