Export to Excel

Need to quickly export some data to Excel? How about doing it in just a couple of lines of code?

Excel Export Plugin is a Rails plugin to do just that.

Install the plugin:
ruby script/plugin install http://svn.napcsweb.com/public/excel

Here is an example method:


def export_project_to_excel
e = Excel::Workbook.new
@project = Project.find(:all)
e.addWorksheetFromActiveRecord "Project", "project", @project
headers['Content-Type'] = "application/vnd.ms-excel"
render_text(e.build)
end

About this article

written on
posted in Rails Back to Top

About the Author

Andrew Turner is an advocate of open standards and open data. He is actively involved in many organizations developing and supporting open standards, including OpenStreetMap, Open Geospatial Consortium, Open Web Foundation, OSGeo, and the World Wide Web Consortium. He co-founded CrisisCommons, a community of volunteers that, in coordination with government agencies and disaster response groups, build technology tools to help people in need during and after a crisis such as an earthquake, tsunami, tornado, hurricane, flood, or wildfire.