SaravanaKumAr
SaravanaKumAr

Reputation: 427

How to download excel file with Angular4 and Rails API?

I have Rails API and Angular 4 Application. Users having Excel reports, These reports are available only for authenticated users Only.

Rails API will have data for the report. Angular app should get the data from Rails API and should download the Excel File.

Kindly give me advice how to implement this? Appreciate your answers.

Upvotes: 0

Views: 199

Answers (1)

Sandeep Garg
Sandeep Garg

Reputation: 1276

You can hit a API which will download the excel file. In order to do so you just need set specific header to download Excel file. here are

   def show
    respond_to do |format|
       format.html { # render normal show here }
       format.xls { # render excel file here }
    end
   end

And make http://localhost:3000/data/5.xls request from your angular app which will prompt to download excel file

Upvotes: 1

Related Questions