Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Making a xls with keys using spreedsheet
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
CHANGELOG
MIT-LICENSE
README.rdoc
Rakefile
VERSION
init.rb
to_xls-rails.gemspec

README.rdoc

to_xls plugin

This simple plugin gives you the ability to call to_xls to a collection of activerecords. The builder options are the same as to_json / to_xml, except for the :include.

Usage

add below to RAILS_ROOT/config/initializers/mime_types.rb
Mime::Type.register_alias "text/excel", :xls

@posts = Post.all

#
#  default are export header and all fileds
#

@posts.to_xls
@posts.to_xls(:fields => you_model_keys)

Example

neel ColumnName  model with keys => :model_name , :column_name ,:print_number

class PostsController < ApplicationController
  def index
    @posts = Post.all

    respond_to do |format|
      format.xls { send_data(@posts.to_xls) }
      #format.xls {

# filename = “posts-#{Time.now.strftime(”%Y%m%d%H%M%S“)}.xls”

      #  send_data(@posts.to_xls(:fields => you_database_keys), :type => "application/excel; charset=utf-8; header=present", :filename => filename)
      #}
    end
  end
end

Dependencies

gem install spreadsheet

git clone http://github.com/jrices/j-provider.git

Install

only with git
git clone http://github.com/wenke/to_xls_with_key.git

Note

Copyright © 2010 liangwenke8@gmail.com, released under the MIT license

Something went wrong with that request. Please try again.