Answer the question
In order to leave comments, you need to log in
How to request to download an excel file?
I have a nodejs request to generate a report in excel. Now you need to use angular to make it possible to download it. How to do it right? At the moment, instead of an excel file, I have a broken html file downloaded.
service:
getReportDate(report_date: string): Observable<any> {
return this.http.get(`${environment.url}/api/report/${report_date}`, { responseType: 'blob' })
}
import { saveAs } from 'file-saver';
selectedDate: string = moment().format('YYYY-MM-DD');
onSelectDate(event): void {
this.selectedDate = moment(event).format('YYYY-MM-DD')
}
report() {
this._homeService.getReportDate(this.selectedDate).subscribe(() => {
saveAs(`report-${moment( this.selectedDate).format('DD.MM.YYYY')}}.xlsx`);
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question