Staging copy. The live site is highearthorbit.com.

Aug 19, 2006 · Rails

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

Rails