Saving Files on the Server
The Excel Export component enables you to send the generated Excel file to a remote service.
To save a file on the server:
- Use the
toDataURL
method to get the base64-encoded contents. - Post the contents to the server.
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import { products } from './products';
@Component({
selector: 'my-app',
template: `
<button type="button" (click)="save(excelexport)">Save</button>
<kendo-excelexport [data]="data" [fileName]="fileName" #excelexport>
<kendo-excelexport-column field="ProductID">
</kendo-excelexport-column>
<kendo-excelexport-column field="ProductName">
</kendo-excelexport-column>
</kendo-excelexport>
`
})
export class AppComponent {
public data: any[] = products;
public fileName: string = "Products.xlsx";
constructor(private http: Http) {
}
public save(component: any): void {
component.toDataUrl().then((dataURL: string) => {
const base64 = dataURL.split(";base64,")[1];
this.http.post(SAVE_URL, {
base64: base64,
fileName: this.fileName
});
});
}
}