Grid values not being exported to Excel when using ng-template

When I use ng-template in ejs-grid, the values are all displayed correctly, but the data.types[column.index].code value is not exported to Excel.

<e-columns>
          <e-column field="description" headerText="Name" [allowFiltering]="true"></e-column>
          <ng-container *ngFor="let column of columns">
            <e-column headerText="{{ column.headerText }}" [allowFiltering]="false" width="50">
              <ng-template #template let-data>
                {{ data.types[column.index].code }}
              </ng-template>
            </e-column>
          </ng-container>

3 Replies

SK Sujith Kumar Rajkumar Syncfusion Team March 9, 2022 12:05 PM UTC

Hi Ed, 

Greetings from Syncfusion support. 

The Grid custom content and styles defined through column template will not be exported to excel file. This is because the Grid excel export draws value on the exported document from the Grid data source and so it does not export custom content by default. 

However you can export the text content defined  in the column template by setting its corresponding value to the value property of the excelQueryCellInfo(Triggers for each cell before exporting to excel) event. 

This is demonstrated in the below code snippet for your reference, 

// Grid’s toolbarClick event handler 
toolbarClick(args: ClickEventArgs): void { 
    if (args.item.text === 'Excel Export') { 
        this.index = 0; 
        this.grid.excelExport(); 
    } 
} 
 
// Grid's  excelQueryCellInfo event handler 
exportQueryCellInfo(args: ExcelQueryCellInfoEventArgs): void { 
    if (args.column.headerText === 'Index') { 
        // Here you can provide the template text content for the Grid cell 
        args.value = "" + this.index; 
        this.index++; 
    } 
} 

We have prepared a sample based on this for your reference. You can find it below, 
 


Please get back to us if you require any further assistance. 

Regards, 
Sujith R 



EC Ed Courtney March 9, 2022 07:41 PM UTC

Yes, this is what I needed. Thank you!



SK Sujith Kumar Rajkumar Syncfusion Team March 10, 2022 07:31 AM UTC

Hi Ed, 
 
You’re welcome. We are glad to hear that your query has been resolved. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon