New to Kendo UI for Angular? Start a free 30-day trial
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.
ts
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/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: HttpClient) {
}
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
}).subscribe();
});
}
}