ZachyBear ZachyBear - 11 months ago 38
SQL Question

Exporting data from Rails into XML and Excel

I use RubyOnRails and I want to get the data from within my database into an XML or Excel format.

How can I do it?


Exporting to XML is simple, you can call to_xml method on your items and render the result or use render :xml

So for example, in your controller:

respond_to do |format|
    format.xml { render xml: @items }

When it comes to Excel, there is a railscast on exporting to CSV (which can be easily imported to Excel) and XLS.