Kendo UI for Angular 2: Excel export having multiple worksheets

左心房为你撑大大i 提交于 2020-01-16 18:28:12

问题


I'm trying to implement an excel-export having multiple worksheets. I was not able to get a solution (example) on the Kendo page itself. In the API documentation I found the possibility to access to the workbook options.

How can I create an excel having 2 or more sheets?

Currently I'm trying it using a simple example from the Kendo page: https://www.telerik.com/kendo-angular-ui/components/excelexport/


回答1:


Using the example provided in the Kendo Demo, you can create an ExcelExportComponent instance for each sheet and merge them in a single file as below (see code in Plunker):

import { Component } from '@angular/core';
import { products } from './products';

@Component({
    selector: 'my-app',
    template: `
        <button type="button" class="k-button" (click)="doExcelExport([excelexport1,excelexport2])">Export To Excel</button>

        <kendo-excelexport [data]="data" fileName="Prod1.xlsx" #excelexport1>
            <kendo-excelexport-column field="ProductID" title="Product ID">
            </kendo-excelexport-column>
            <kendo-excelexport-column field="ProductName" title="Product Name">
            </kendo-excelexport-column>
      </kendo-excelexport>
      <kendo-excelexport [data]="data" fileName="Prod2.xlsx" #excelexport2>
            <kendo-excelexport-column field="ProductID" title="Product ID">
            </kendo-excelexport-column>
            <kendo-excelexport-column field="ProductName" title="Product Name">
            </kendo-excelexport-column>
      </kendo-excelexport>
    `
})
export class AppComponent {
    public data: any[] = products;

   public doExcelExport(components: ExcelExportComponent[]): void {

        var options = components[0].workbookOptions();
        if (components.length > 1){
            for (var x = 1; x < components.length; x++) {
                options.sheets[x] = components[x].workbookOptions().sheets[0];
            }
        }
        components[0].save(options);
    }
}


来源:https://stackoverflow.com/questions/46890711/kendo-ui-for-angular-2-excel-export-having-multiple-worksheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!