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

Excel Export

The TreeList enables you to export its content to Excel.

For a runnable example, refer to the demo on Excel export by the TreeList.

Getting Started

To enable the Excel export option of the TreeList:

  1. Include the corresponding toolbar command and set the export settings.
  2. To take full advantage of the Excel export feature, download the JSZip library and include the file before the Kendo UI JavaScript files in the Layout.cshtml. For more information, refer to the article with the requirements.

        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="https://unpkg.com/jszip/dist/jszip.min.js"></script>
        <script src="https://kendo.cdn.telerik.com/2024.1.319/js/kendo.all.min.js"></script>
    
        @(Html.Kendo().TreeList<Kendo.Mvc.Examples.Models.TreeList.EmployeeDirectoryModel>()
            .Name("treelist")
            .Toolbar(tools => tools.Excel())
            .Excel(excel => excel.FileName("Kendo UI TreeList Export.xlsx").ProxyURL(Url.Action("Excel_Export_Save")))
            .DataSource(dataSource => dataSource
                .Read(read => read.Action("All", "EmployeeDirectory"))
            )
        )
    

To initiate the Excel export, press the Toolbar button or use the TreeList client-side API and call the saveAsExcel method.

Outputting the Result

Through its default configuration, the Telerik UI TreeList for ASP.NET MVC exports the current page of the data with sorting, filtering, and aggregates applied. To export all pages, refer to this section.

The TreeList 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.

  • The TreeList exports only data-bound columns. Template and command columns are ignored.
  • The ClientTemplate option is not used during export.

Exporting All Data

By default, the Telerik UI TreeList for ASP.NET MVC exports only the current page of data. To export all pages, set the AllPages option to true.

    @(Html.Kendo().TreeList<Kendo.Mvc.Examples.Models.TreeList.EmployeeDirectoryModel>()
        .Name("treelist")
        .Toolbar(tools => tools.Excel())
        .Excel(excel => excel.AllPages(true))
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("All", "EmployeeDirectory"))
        )
    )

See Also

In this article