剑道UI的角2:具有Excel导出多个工作表(Kendo UI for Angular 2: Exc

2019-10-29 21:59发布

我试图实现具有多个工作表的Excel出口。 我是不是能够得到剑道网页上看到的解决方案(例如)。 在API文档,我发现进入到工作簿选项的可能性。

如何创建具有2代以上表的Excel?

目前我使用从剑道页一个简单的例子尝试它: https://www.telerik.com/kendo-angular-ui/components/excelexport/

Answer 1:

利用在剑道演示提供的示例中,可以为每个片创建ExcelExportComponent实例,并在一个文件中如下面(参照代码合并它们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);
    }
}


文章来源: Kendo UI for Angular 2: Excel export having multiple worksheets