问题
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