Server out to excel

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

Tom W. wrote:

On 5/18/06, Glenn C. [email protected] 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”

On 5/18/06, Glenn C. [email protected] 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

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 = “

13445 123 456
789
=23+456 =987-654

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

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 C. [email protected] wrote:

class ExcelController < ApplicationController

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

you would put send_data in a seperate controller, then the “View in
Excel” button would link to that controller.
-N

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 C. [email protected] wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

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 C. [email protected] wrote:

class ExcelController < ApplicationController

Rails mailing list
[email protected]
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.