Exporting Multiple Data Sets to Separate Excel Sheets
Environment
Product | Progress® Kendo UI for Angular Excel Export |
Description
How can I export multiple data sets to individual workbook sheets in the Kendo UI for Angular Excel Export?
Solution
You can obtain references to the respective ExcelExport components and use custom logic to merge the individually generated workbooks of the separate components into one.
-
Obtain references to the respective ExcelExport components by using the template reference variables or, for example,
ViewChild
. -
Merge the generated workbook sheets into one and export their content by using the
save() method
.tspublic save(component1, component2): void { Promise.all([component1.workbookOptions(), component2.workbookOptions()]).then((workbooks) => { workbooks[0].sheets = workbooks[0].sheets.concat(workbooks[1].sheets); component1.save(workbooks[0]); }); }
The following example demonstrates the full implementation of the suggested approach.
When the number of datasets that will be exported to a separate sheet is not known in advance, you can extend the suggested approach to create multiple ExcelExport components over *ngFor
and map them to a collection of WorkbookOptions
that can be exported to a single file with separate sheets.