hello, 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..? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
http://wiki.rubyonrails.com/rails/pages/HowToExportToExcel -Shawn On 3/19/07, Ro Vent <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > hello, > > 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..? > > > Thanks > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:>> 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") > endI am having problems adapting my query for use with your code.. @days_done = Boards.find_by_sql "select id, work_order, TO_DAYS(updated_at) - TO_DAYS(created_at) as Age, created_at, updated_at, notes from boards where done = 1 order by TO_DAYS(updated_at) - TO_DAYS(created_at) DESC" Any ideas...? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Don''t forget that there''s always the option of just rendering an HTML table but reporting the content-type as application/vnd.ms-excel . Then when someone wants a .xls document you just render an html table without a layout and Excel (as well as OpenOffice) will open the file up as a single-sheet excel document. I''ve yet to get this method to work with Google Spreadsheets or Gnumeric though. First register the MIME type in environment.rb: Mime::Type.register "application/vnd.ms-excel", :xls, [ "application/excel", "application/x-excel" ] Then you can just have a respond_to block with wants.xls? rendering with no layout. Provided you are setup in such a way that the convention of this works for you. It might take a little more work in your own application. Taylor Singletary Reality Technician http://www.realitytechnicians.com On 3/20/07, Ro Vent <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Philip Hallstrom wrote: > >> 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 > > I am having problems adapting my query for use with your code.. > @days_done = Boards.find_by_sql "select id, work_order, > TO_DAYS(updated_at) - TO_DAYS(created_at) as Age, created_at, > updated_at, notes from boards where done = 1 order by > TO_DAYS(updated_at) - TO_DAYS(created_at) DESC" > > Any ideas...? > > Thanks > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---