New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Export Multiple TreeLists to Excel
Environment
Product | TreeList for Telerik UI for ASP.NET MVC |
Product Version | Created with version 2024.4.1112 |
Description
How can I export multiple ASP.NET MVC TreeList components to a single Excel document?
Solution
In this example, each TreeList is exported to a separate Excel sheet. For more information on the Excel generation, refer to the Excel export overview article.
- Create an external button to export the TreeLists data when it is clicked.
- Use the client-side
saveAsExcel()
method to trigger the data export of each TreeList. - Handle the
ExcelExport
event of the TreeLists and prevent its default action. - Create a new Workbook that contains the sheets with the TreeLists data and save it through the
kendo.saveAs()
method.
Razor
<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/2.4.0/jszip.min.js"></script>
<button class="k-button k-button-md k-rounded-md k-button-solid k-button-solid-base" id="export">Export TreeLists to Excel</button>
<h3>Designers</h3>
@(Html.Kendo().TreeList<Telerik.Examples.Mvc.Areas.TreeListExportingMultiple.Models.EmployeeDirectoryModel>()
.Name("designers")
.Events(e => e.ExcelExport("onExcelExportDesigners"))
... // Additional configuration.
)
<h3>Lead personnel</h3>
@(Html.Kendo().TreeList<Telerik.Examples.Mvc.Areas.TreeListExportingMultiple.Models.EmployeeDirectoryModel>()
.Name("leads")
.Events(e => e.ExcelExport("onExcelExportLead"))
... // Additional configuration.
)
For a runnable example, refer to the ASP.NET MVC application on how to export the data of multiple TreeLists in a single Excel document.