Export data to Excel (xls) in Ruby on Rails

The code Below will help to export the data in excel in Ruby on Rails


class UserController < ApplicationController
  def export
    headers['Content-Type'] = "application/vnd.ms-excel"
    headers['Content-Disposition'] = 'attachment; filename="report.xls"'
    headers['Cache-Control'] = ''
    @users = User.find(:all)



<%= link_to "Export as Excel", export_person_url %>


<table border="1">
  <% @users.each do |u| %>
   <td><%= u.name %></td>
  <% end %>

Please note :- This method might might be deprecated. You may visit http://spreadsheet.rubyforge.org/ for more info. Thanks

Be Sociable, Share!