New to Telerik UI for ASP.NET Core? 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.3.806/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"))
            )
        )
    
        <kendo-treelist name="treelist">
            <toolbar>
                <treelist-toolbar-button name="excel"/>
            </toolbar>
            <excel file-name="Kendo UI TreeList Export.xlsx" proxy-url="@Url.Action("Excel_Export_Save","TreeList")"/>
            <treelist-datasource>
                <transport>
                    <read url="@Url.Action("All","EmployeeDirectory")"/>
                </transport>
                ...
            </treelist-datasource>
            <!-- Other configuration. -->
        </kendo-treelist>
    

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 Core 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 Core 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"))
        )
    )
    <kendo-treelist name="treelist">
        <toolbar>
            <treelist-toolbar-button name="excel"/>
        </toolbar>
        <excel all-pages="true"/>
        <treelist-datasource>
            <transport>
                <read url="@Url.Action("All","EmployeeDirectory")"/>
            </transport>
            ...
        </treelist-datasource>
        <!-- Other configuration. -->
    </kendo-treelist>

See Also

In this article