I was wondering if there is a way to create an excel file with ROR..?
Here is what i have: The app i have has a reports section, that section has many reports that use the find_by_sql in order to customize the query. On the main reports page the use is able to click and a report link and it opens up a new window displaying the data i want to be able to have a link that when clicked it creates an excel file that the user can download.
Is there any way to accomplish that..?
If you'll settle for a CSV that will open up in Excel, then it's pretty easy... here's an example out of our site
entry = VideoGalleryEntry.find_by_id(params[:id]) Tempfile.open("video-gallery-report-#{entry.id}") do |t| CSV::Writer.generate(t, ',') do |csv| csv << ["Date", "Number of Views"] entry.views.sort {|a,b| a.viewed_on <=> b.viewed_on }.each do |v| csv << [v.viewed_on, v.views] end end t.size t.rewind send_data(t.read, :type => 'application/vnd.ms-excel; charset=iso-8859-1; header=present', :filename => "video-gallery-report-#{entry.id}.csv") end