I''m looking to add an "Export to Excel" feature to my Rails app. I''ve implemented an "Export to XML" action, which uses the XML Builder stuff in rails, and it works fine except that the user has to jump through a few hoops to get the XML into Excel 1) click Export to XML which sends XML to the browser for display - ugly 2) click Save File As to save XML 3) click the Back button to return to the app 4) open the XML in Excel I''d like to improve on this process if possible, perhaps by: A) somehow telling the browser that the XML from 1) is to be saved, not displayed B) perhaps ZIPPing the XML from 1) first This would eliminate 2) and 3) from the process. Can anyone point me in the right direction ? Thanks Neville _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 9/21/05, Neville Burnell <Neville.Burnell-uEDVyssJ3mUpAS55Wn97og@public.gmane.org> wrote:> I''d like to improve on this process if possible, perhaps by: > > A) somehow telling the browser that the XML from 1) is to be saved, not > displayed > B) perhaps ZIPPing the XML from 1) first > > This would eliminate 2) and 3) from the process. > > Can anyone point me in the right direction ?Have you tried setting the disposition (using #send_data)? You''d send as data the output for Builder::XmlMarkup. You want a disposition of ''attachment''. Leon
Thanks Leon, I''ll take a look -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of leon breedt Sent: Wednesday, 21 September 2005 11:44 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Generating XML for ''export to Excel'' On 9/21/05, Neville Burnell <Neville.Burnell-uEDVyssJ3mUpAS55Wn97og@public.gmane.org> wrote:> I''d like to improve on this process if possible, perhaps by: > > A) somehow telling the browser that the XML from 1) is to be saved, > not displayed > B) perhaps ZIPPing the XML from 1) first > > This would eliminate 2) and 3) from the process. > > Can anyone point me in the right direction ?Have you tried setting the disposition (using #send_data)? You''d send as data the output for Builder::XmlMarkup. You want a disposition of ''attachment''. Leon _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Wednesday 21 Sep 2005 02:23, Neville Burnell wrote:> I''m looking to add an "Export to Excel" feature to my Rails app.Someone has already done the work for you: http://wiki.rubyonrails.com/rails/show/HowToExportToExcel I implemented this yesterday (and slightly edited the Wiki entry too), and have also just made a CSV version since I don''t think my client has the latest Office versions. Anyway, the Wiki seems to be down at the moment, but Google for "rails excel xml" and use the Google cache (although it''s not been updated with the things I changed yesterday) - basically, just make sure you disable your layout. Also, to do it as a download rather than display in the browser, try something like this in your controller: headers[''Content-Type''] = "application/vnd.ms-excel" headers[''Pragma''] = "no-cache" headers[''Cache-Control''] = "no-cache, must-revalidate" headers[''Expires''] = "0" headers[''Content-Disposition''] = "attachment; filename=foobar.xls" Although come to think of it, if you''re using Windows and Internet Explorer and MS Office (me: Linux, Firefox, OpenOffice), that could be why it''s showing in the browser, but that''s your own browser settings, not the server, so you''ll still need to right-click-save-as to get it to work (or change your browser settings). Cheers, ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
Thanks Dave -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Dave Silvester Sent: Wednesday, 21 September 2005 8:46 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Generating XML for ''export to Excel'' On Wednesday 21 Sep 2005 02:23, Neville Burnell wrote:> I''m looking to add an "Export to Excel" feature to my Rails app.Someone has already done the work for you: http://wiki.rubyonrails.com/rails/show/HowToExportToExcel I implemented this yesterday (and slightly edited the Wiki entry too), and have also just made a CSV version since I don''t think my client has the latest Office versions. Anyway, the Wiki seems to be down at the moment, but Google for "rails excel xml" and use the Google cache (although it''s not been updated with the things I changed yesterday) - basically, just make sure you disable your layout. Also, to do it as a download rather than display in the browser, try something like this in your controller: headers[''Content-Type''] = "application/vnd.ms-excel" headers[''Pragma''] = "no-cache" headers[''Cache-Control''] = "no-cache, must-revalidate" headers[''Expires''] = "0" headers[''Content-Disposition''] = "attachment; filename=foobar.xls" Although come to think of it, if you''re using Windows and Internet Explorer and MS Office (me: Linux, Firefox, OpenOffice), that could be why it''s showing in the browser, but that''s your own browser settings, not the server, so you''ll still need to right-click-save-as to get it to work (or change your browser settings). Cheers, ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails