This is a migrated thread and some comments may be shown as answers.

Remove a Column Upon Export to Excel

1 Answer 1072 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Charles
Top achievements
Rank 1
Veteran
Charles asked on 27 May 2020, 05:14 AM

app.component.ts:

import { Component } from '@angular/core';
import { process } from '@progress/kendo-data-query';
import { ExcelExportData } from '@progress/kendo-angular-excel-export';
import { products } from './products';
 
@Component({
    selector: 'my-app',
    template: `
        <kendo-grid [kendoGridBinding]="products" [height]="400" [pageable]="true" [pageSize]="10">
            <ng-template kendoGridToolbarTemplate>
                <button type="button" kendoGridExcelCommand icon="file-excel">Export to Excel</button>
            </ng-template>
            <kendo-grid-column field="ProductID" title="Product ID" [width]="200">
            </kendo-grid-column>
            <kendo-grid-column field="ProductName" title="Product Name">
            </kendo-grid-column>
            <kendo-grid-column field="Category.CategoryName" title="Category">
            </kendo-grid-column>
        <kendo-grid-excel fileName="Products.xlsx" [fetchData]="allData"></kendo-grid-excel>
      </kendo-grid>
    `
})
export class AppComponent {
    public products: any[] = products;
 
    public group: any[] = [{
        field: 'Category.CategoryName'
    }];
 
    // Bind 'this' explicitly to capture the execution context of the component.
    constructor() {
        this.allData = this.allData.bind(this);
    }
 
    public allData(): ExcelExportData {
        const result: ExcelExportData =  {
            data: process(products, { group: this.group, sort: [{ field: 'ProductID', dir: 'asc' }] }).data,
            group: this.group
        };
 
        return result;
    }
}

 

Given the code above, how can I remove a column (Product ID, Product Name or Category) upon exporting it to excel?

1 Answer, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 28 May 2020, 09:18 AM

Hi Charles,

The developer can set all columns that need to end up in the exported document by declaring them as nested kendo-excelexport-column tags within the kendo-grid-excel tag as demonstrated in the following documentation example:

https://www.telerik.com/kendo-angular-ui/components/grid/export/excel-export/#toc-customizing-exported-columns

I hope this helps.

Regards,
Dimiter Topalov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
General Discussions
Asked by
Charles
Top achievements
Rank 1
Veteran
Answers by
Dimiter Topalov
Telerik team
Share this question
or