D
D
ds32019-11-15 12:25:10
Angular
ds3, 2019-11-15 12:25:10

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' })
    }

component:
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

1 answer(s)
A
Andrew, 2019-11-15
@ds3

So you formulate the request correctly.
What method and parameters do you have there (on the back)?

getReportDate(report_date: string): Observable<any> {
        return this.http.get(`${environment.url}/api/report/?param=${report_date}`, { responseType: 'blob' })
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question