Sha256: bbdb77975268cd480afc5b8b8cd9eb67124b91c403e883c06c4275c0bc311eea
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
= to_xls gem This gem transform an Array into a excel file using the spreadsheet gem. == Usage @users = User.all # # defaults are export headers and all fields # @users.to_xls @users.to_xls(:headers => false) @users.to_xls(:columns => [:name, :role]) @users.to_xls(:columns => [:name, {:company => [:name, :address]}]) @users.to_xls(:columns => [:name, {:company => [:name, :address]}], :headers => [:name, :company, :address]) == Requirements In config/initializers/mime_types.rb register the custom mime type. Mime::Type.register "application/vnd.ms-excel", :xls == How to use In the controller where you want to export to excel, add the format.xls line. class UserController < ApplicationController def index @users = User.all respond_to do |format| format.html format.xml { render :xml => @users } format.xls { send_data @users.to_xls } end end def show... def new... def edit... def create... def update... def destroy... end == Dependencies spreadsheet gem == Install Include this gem in your environment.rb config file: config.gem 'to_xls'
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
to_xls-0.0.2 | README.rdoc |
to_xls-0.0.1 | README.rdoc |