Difficulty with send_data in Ruby on Rails in conjunction with Spreadsheet plug-in

后端 未结 2 1137
一个人的身影
一个人的身影 2021-01-02 18:11

I have a function in a controller that takes in some specifications and generates a report on them. This function user_report is called in a view:

< %= submit_to

相关标签:
2条回答
  • 2021-01-02 18:16

    Even though I dont like to write and delete , but with spreadsheet seems like the only solution.


      # write the file
    
     book.write "Employee_History_#{ params[:id]}.xls"
    
     # send the file
    
     send_file "Employee_History_#{ params[:id]}.xls", :type => "application/vnd.ms-excel", :filename => "data.xls", :stream => false
    
     # and then delete the file
    
     File.delete("Employee_History_#{ params[:id]}.xls")
    
    0 讨论(0)
  • 2021-01-02 18:30

    Just change the line:

    send_data data.string, :type=>"application/excel", :disposition=>'attachment', :filename => @outfile
    

    to:

    send_data data.string.bytes.to_a.pack("C*"), :type=>"application/excel", :disposition=>'attachment', :filename => @outfile
    
    0 讨论(0)
提交回复
热议问题