Serguei Cambour wrote in post #968794:
> I used the following way to generate an Excel file for reports:
>
> 1; In the controller:
>
> [code]
> def exports
> @projects = Project.find(params[:project_ids])
> headers['Content-Type'] = "application/vnd.openxmlformats-
> officedocument.spreadsheetml.sheet.main+xml"
> headers['Content-Disposition'] = "inline; filename=\"reports-
> #{Date.today.to_s}.xls\""
> headers['Cache-Control'] = ''
>
> render :layout => false
> end
> [/code]
>
> In the view 'exports.rxml'
>
> [code]
> xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
>
> workbook_xmlns = {
> 'xmlns' => "urn:schemas-microsoft-com:office:spreadsheet",
> 'xmlns:o' => "urn:schemas-microsoft-com:office:office",
> 'xmlns:x' => "urn:schemas-microsoft-com:office:excel",
> 'xmlns:html' => "http://www.w3.org/TR/REC-html40",
> 'xmlns:ss' => "urn:schemas-microsoft-com:office:spreadsheet"
> }
>
> xml.Workbook(workbook_xmlns) do
>
> xml.Styles do
> xml.Style 'ss:ID' => 's22' do
> xml.NumberFormat 'ss:Format' => 'yyyy\-mm\-dd'
> end
> xml.Style 'ss:ID' => 's21' do
> xml.NumberFormat 'ss:Format' => '#,##0.00\ [$]'
> end
> end
>
> xml.DocumentProperties({'xmlns' => "urn:schemas-microsoft-
> com:office:office"}) do
> xml.Author current_user.login
> xml.Created Time.now
> xml.Company 'UCB'
> xml.Version '11.4920'
> end
>
>
> xml.Worksheet 'ss:Name' => 'Reports' do
>
> xml.Table do
>
> # Header
> xml.Row do
> xml.Cell do
> xml.Data "Tax/Non-tax", 'ss:Type' => 'String'
> end
> ...
> and so on, adding cells, rows whatever you want.
>
> [/code]
Thanks, Sergui and Marnen. It looks like providing the xml file with the
Excel 'decorations' may be the best way. It's pretty seamless in Excel
2003.
The Spreadsheet gem only accepts text for cell contents, so you end up
with a lot of "number stored as text" notifications. I guess if I needed
to read/modify an existing Excel document, Spreadsheet might have been
my best bet.
For now, though, I guess the MS-xml approach might be best. I will be
assimilated. At least I can put the builder code in the views, where I
think we all agree it belongs.
Ron
Ron
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment