How would one server out to excel a html table with the mime/content type application/vnd.ms-excel ? In PHP it would be something like ?php header("Content-Type: application/vnd.ms-excel"); ------ But how do I do this in rails? Cheers Glenn -- Posted via http://www.ruby-forum.com/.
On 5/18/06, Glenn Cadman <glenn.cadman@gmail.com> wrote:> How would one server out to excel a html table with the mime/content > type > application/vnd.ms-excel ?send_data(excel_data, :type => "application/vnd.ms-excel", :filename => filename) Where excel_data is the data you want to send, and filename is the suggested filename for the data. Tom
Tom Ward wrote:> On 5/18/06, Glenn Cadman <glenn.cadman@gmail.com> wrote: >> How would one server out to excel a html table with the mime/content >> type >> application/vnd.ms-excel ? > > send_data(excel_data, :type => "application/vnd.ms-excel", :filename > => filename) > > Where excel_data is the data you want to send, and filename is the > suggested filename for the data. > > TomSorry to ask a real dumb question, but where would I put the send_data command? I have a mylist.rhtml which presently creates a formated table list as html. I want a button that says "View in Excel", that more or less renders mylist.rhtml without the standard wrapping layout. When the user clicks "View in Excel" my.rhtml is rendered but this time browser receives http header of "application/vnd.ms-excel" rather than the default of "text/html" -- Posted via http://www.ruby-forum.com/.
you would put send_data in a seperate controller, then the "View in Excel" button would link to that controller. -N On 19/05/06, Glenn Cadman <glenn.cadman@gmail.com> wrote:> Tom Ward wrote: > > On 5/18/06, Glenn Cadman <glenn.cadman@gmail.com> wrote: > >> How would one server out to excel a html table with the mime/content > >> type > >> application/vnd.ms-excel ? > > > > send_data(excel_data, :type => "application/vnd.ms-excel", :filename > > => filename) > > > > Where excel_data is the data you want to send, and filename is the > > suggested filename for the data. > > > > Tom > > > Sorry to ask a real dumb question, but where would I put the send_data > command? > > I have a mylist.rhtml which presently creates a formated table list as > html. > I want a button that says "View in Excel", that more or less renders > mylist.rhtml without the standard wrapping layout. When the user clicks > "View in Excel" my.rhtml is rendered but this time browser receives http > header of "application/vnd.ms-excel" rather than the default of > "text/html" > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
unknown wrote:> you would put send_data in a seperate controller, then the "View in > Excel" button would link to that controller. > -NWell I am feeling really brain dead now. The following calls up excel nicely and displays a number of fields. ---------- class ExcelController < ApplicationController def doexcel mytext = "<table><tr><td>13445<td>123<td> 456<td> 789<td>=23+456<td>=987-654</tr></table>" send_data mytext, :type => ''application/vnd.ms-excel'', :disposition => ''inline'' end end ----------- But how would I get the text string data created from a .rhtml template or partial to the send_data command. Basically I want a single template that will look more or less the same in the browser as in the excel? I will be creating a long list of outstanding orders in the browser that the user may want to view in Excel -- Posted via http://www.ruby-forum.com/.
Well... If you want to simply rerender the mylist view and send it you can do this. def doexcel mytext = render :action => mylist send_data mytext, :type => ''application/vnd.ms-excel'', :disposition => ''inline'' end On 5/19/06, Glenn Cadman <glenn.cadman@gmail.com> wrote:> unknown wrote: > > you would put send_data in a seperate controller, then the "View in > > Excel" button would link to that controller. > > -N > > Well I am feeling really brain dead now. > > The following calls up excel nicely and displays a number of fields. > > ---------- > class ExcelController < ApplicationController > > def doexcel > mytext = "<table><tr><td>13445<td>123<td> 456<td> > 789<td>=23+456<td>=987-654</tr></table>" > send_data mytext, :type => ''application/vnd.ms-excel'', :disposition > => ''inline'' > end > > end > ----------- > > But how would I get the text string data created from a .rhtml template > or partial to the send_data command. Basically I want a single template > that will look more or less the same in the browser as in the excel? > > I will be creating a long list of outstanding orders in the browser that > the user may want to view in Excel > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/
J?n Borg??rsson wrote:> Well... If you want to simply rerender the mylist view and send it you > can do this. > > def doexcel > mytext = render :action => mylist > send_data mytext, :type => ''application/vnd.ms-excel'', :disposition > => ''inline'' > end > > > On 5/19/06, Glenn Cadman <glenn.cadman@gmail.com> wrote: >> class ExcelController < ApplicationController >> >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > --Genius, Solved!!! ....it is working well. My brain just seems to have a big block in "thinking ROR", I have no idea why it works! I would have guessed that the render action calls the view processes that renders out the text stream to the to webserver after which processing is resumed in the controller. I would have guessed that mytext = render :action => mylist would set the value of mylist to the return code (success or failure) of the render action, rather than the text stream of the render action. -- Posted via http://www.ruby-forum.com/.
Remember. Everything is an object. This was the single thing I had the biggest problems with when I stopped thinking in PHP and started thinking in Ruby. There is no difference between the class render and the class integer or the class string. On 5/19/06, Glenn Cadman <glenn.cadman@gmail.com> wrote:> J?n Borg??rsson wrote: > > Well... If you want to simply rerender the mylist view and send it you > > can do this. > > > > def doexcel > > mytext = render :action => mylist > > send_data mytext, :type => ''application/vnd.ms-excel'', :disposition > > => ''inline'' > > end > > > > > > On 5/19/06, Glenn Cadman <glenn.cadman@gmail.com> wrote: > >> class ExcelController < ApplicationController > >> > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > -- > > Genius, Solved!!! ....it is working well. > > My brain just seems to have a big block in "thinking ROR", I have no > idea why it works! I would have guessed that the render action calls the > view processes that renders out the text stream to the to webserver > after which processing is resumed in the controller. > > I would have guessed that mytext = render :action => mylist would set > the value of mylist to the return code (success or failure) of the > render action, rather than the text stream of the render action. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/