views:

37

answers:

1

This is when using a view file to generate an excel file. like: in controller:

headers['Content-Type'] = "application/vnd.ms-excel"
headers['Content-Disposition'] = 'attachment; filename="report.xls"'

then in view:

<table><tr><td>foo</td><td>bar</td></tr><table>

Is it possible to add formatting such as color to cells? like:

<td style="background-color=red">foo</td>
+1  A: 

Interesting -- I didn't know you could make Excel spreadsheets through HTML tables. (I just tried it myself and was amazed.) I don't think CSS will work very reliably -- you're probably stuck with HTML as it existed around HTML 3.2 (circa 1996). Although I cringe a little writing it, this worked for me:

<td bgcolor="red">foo</td>

or

<td bgcolor="#f00">foo</td>

I tested this in OpenOffice.org 3.2.

That being said, it might be worth learning the MS Office XML format if you need a lot of control over formatting. If I remember correctly, you can apply the formatting yourself in Excel, then unzip the .xlsx file, and see what it wrote out.

Benjamin Oakes
thanks for answering! never occured to me to use bgcolor! will try it out and see if it works.
paolo granada lim
it works! thanks a lot!
paolo granada lim
Not a problem. Use it with care. :)
Benjamin Oakes