Git:http://github.com/thambley/activeadmin-xls
Author: Todd Hambley
Copyright: 2014 ~ 2016
License: MIT License
Latest Version: 1.0.3
Release Date: 2014.09.21
This gem provides xls downloads for Active Admin resources.
This gem borrows heavily from https://github.com/randym/activeadmin-axlsx and https://github.com/splendeo/to_xls.
Usage example:
Add the following to your Gemfile and you are good to go. All resource index views will now include a link for download directly to xls.
gem 'activeadmin-xls'
Here are a few quick examples of things you can easily tweak.
# app/admin/posts.rb
ActiveAdmin.register Post do
config.xls_builder.i18n_scope = [:active_record, :models, :posts]
end
# app/admin/posts.rb
ActiveAdmin.register Post do
config.xls_builder.column('author_name') do |resource|
resource.author.name
end
end
# app/admin/posts.rb
ActiveAdmin.register Post do
config.xls_builder.header_format = { :weight => :bold,
:color => :blue }
end
# app/admin/posts.rb
ActiveAdmin.register Post do
config.xls_builder.delete_columns :id, :created_at, :updated_at
end
Everything that you do with the config's default builder can be done via the resource DSL.
Below is an example of the DSL
ActiveAdmin.register Post do
# i18n_scope and header style are set via options
xlsx(:i18n_scope => [:active_admin, :xls, :post],
:header_style => {:weight => :bold, :color => :blue }) do
# Specify that you want to white list column output.
# whitelist
# Do not serialize the header, only output data.
# skip_header
# deleting columns from the report
delete_columns :id, :created_at, :updated_at
# adding a column to the report
column(:author) { |resource| "#{resource.author.first_name} #{resource.author.last_name}" }
# creating a chart and inserting additional data with after_filter
after_filter { |sheet|
# todo
}
# iserting data with before_filter
before_filter do |sheet|
# todo
end
end
end
Running specs for this gem requires that you construct a rails application. To execute the specs, navigate to the gem directory, run bundle install and run these to rake tasks:
bundle exec rake setup
bundle exec rake
activeadmin-xls © 2014 by Todd Hambley.
activeadmin-xls is licensed under the MIT license. Please see the LICENSE document for more information.