Status
No public Twitter messages.
Location
Washington, DC
Subscribe to GeoRSS Subscribe to KML


Export to Excel

Published in Rails  |  4 Comments


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

Similar Posts


Responses

  1. Brian says:

    September 7th, 2006 at 10:29 pm (#)

    Thanks for the link to my plugin! Nice site.

  2. andry says:

    May 20th, 2008 at 7:49 am (#)

    ok

  3. khim says:

    December 31st, 2008 at 4:31 am (#)

    I practiced this code with Ruby on Rails 2.9 but It doen’t work. the message show that “uninitialized constant ElectricityController::Excel ” please help me to go on solve this problem by regard….!

  4. manjula says:

    August 28th, 2009 at 6:29 am (#)

    HI,

    I’ve used this plugin with rails 2.3 and getting error as
    undefined method `addWorksheetFromActiveRecord’ for Excel::Workbook:Class

    What is the wrong?Please help me to get it solved

Leave a Response