ℹ️ This is a fork of the official repository who isn't maintained anymore
Excel Spreadsheet Export for Active Admin
This gem provides xls downloads for Active Admin resources.
This gem borrows heavily from activeadmin-axlsx and to_xls.
Add the following to your Gemfile. All resource index views will now include a link for download directly to xls.
gem "activeadmin-xls", git: "https://github.com/Captive-Studio/activeadmin-xls"
For Active Admin 1.0 and above, you will also have to update config/initializers/active_admin.rb. Update the download_links setting to include xls:
config.download_links = %i[csv xml json xls]
This gem depends on spreadsheet to generate xls files.
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
# app/admin/posts.rb
ActiveAdmin.register Post do
config.xls_builder.only_columns :title, :author
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
xls(i18n_scope: [:active_admin, :xls, :post],
header_format: { 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
# restrict columns to a list without customization
# only_columns :title, :author
# deleting columns from the report
delete_columns :id, :created_at, :updated_at
# adding a column to the report with customization
column(:author) { |post| "#{post.author.first_name} #{post.author.last_name}" }
# inserting additional data with after_filter
after_filter do |sheet|
# todo
end
# inserting 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 install --gemfile=gemfiles/rails_42.gemfile
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake setup
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake
bundle install --gemfile=gemfiles/rails_52.gemfile
BUNDLE_GEMFILE=gemfiles/rails_52.gemfile bundle exec rake setup
BUNDLE_GEMFILE=gemfiles/rails_52.gemfile bundle exec rake
bundle install --gemfile=gemfiles/rails_60.gemfile
BUNDLE_GEMFILE=gemfiles/rails_60.gemfile bundle exec rake setup
BUNDLE_GEMFILE=gemfiles/rails_60.gemfile bundle exec rake
This repo is maintained by Captive. The names and logos for captive are trademarks of captive-studio.
We love open source software! See our other projects or hire us to design, develop, and grow your product.