Edit this page

Excel Export

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<.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 for ASP.NET Core 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 for ASP.NET Core 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<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 for ASP.NET Core 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 how-to example.

Define the Column Format

The Kendo UI Grid for ASP.NET Core 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 how-to example.

Use the Detail Template

The Kendo UI Grid for ASP.NET Core 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 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.

See Also

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