Kendo Angular: Export multiple Tree Lists to one Excel sheet

0 Answers 66 Views
Excel Export TreeList
Mahidhar
Top achievements
Rank 1
Mahidhar asked on 28 Apr 2023, 07:20 AM | edited on 28 Apr 2023, 07:24 AM

Hi,

I am trying to export multiple treelists which has same columns and treelists are generated by *ngFor  (from an external button request) into one Excel sheet. I cannot get it quite right, and cannot find any example that can help me.

Any examples or assistance would be greatly appreciated.

Thank you,

Mahidhar.

Yanmario
Telerik team
commented on 02 May 2023, 12:33 PM

Hi Mahidhar,

An answer was provided in our private thread conversation, and for public knowlage I will also share it here.

In general, whenever the default TreeList Excel Export functionality is used, the TreeListdata is automatically converted to an object of the type Workbook. That is the default type of object when creating Excel files manually provided by Microsoft:

https://docs.microsoft.com/en-us/office/vba/api/excel.workbook

One option in order to export two TreeList in the same sheet is to construct the desired Workbook manually. Please check the following article from our documentation demonstrating how to create new Workbooks manually:

https://www.telerik.com/kendo-angular-ui/components/excel-export/workbook/new-custom/

Here is an example demonstrating how to export a custom Workbook that can represent two different table contents:

https://stackblitz.com/edit/angular-pzuctt?file=src%2Fapp%2Fapp.component.ts

Now that can be adjusted depending on the specific use case scenario and will not rely on the TreeList Excel Export functionality.

I will share a second approach, but the developer would possibly need to get all of the TreeList references from the DOM so that the approach could work.

Using the TreeList built-in feature to construct the two separate Workbooks for the two TreeLists and then combine them. Please check the following example demonstrating such an approach:

https://stackblitz.com/edit/angular-hx2qsm?file=src%2Fapp%2Fapp.component.ts

The essential parts in this example are that the (excelExport) event of the first TreeList is prevented. Then the generated Workbook data is saved and then (excelExport) event of the second TreeList is fired by calling the second Grid saveAsExcel() method. Finally, in the (excelExport) event handler function of the second TreeList, the automatically generated Workbooks for both TreeLists are combined. 

Example using ngFor and ViewChildren:

https://stackblitz.com/edit/angular-hx2qsm-s4x1nu?file=src%2Fapp%2Fapp.component.ts

Regards,
Yanmario
Progress Telerik     

No answers yet. Maybe you can help?

Tags
Excel Export TreeList
Asked by
Mahidhar
Top achievements
Rank 1
Share this question
or