Giter VIP home page Giter VIP logo

activeadmin-caxlsx's Introduction

Active Admin Axlsx

Notice: Community Axlsx Organization

To better maintain the Axlsx ecosystem, all related gems have been forked or moved to the following community organization: http://github.com/caxlsx

Join the Caxlsx Slack channel

Synopsis

This gem provides automatic OOXML (xlsx) downloads for Active Admin resources. It lets you harness the full power of Axlsx when you want to but for the most part just stays out of your way and adds a link next to the csv download for xlsx (Excel/numbers/Libre Office/Google Docs)

Screen 1

Install

Add the following to your Gemfile

gem 'activeadmin-axlsx'

All resource index views will now include a link for XLSX download

Localize Column Headers

#app/admin/posts.rb
ActiveAdmin.register Post do
  config.xlsx_builder.i18n_scope = [:active_record, :models, :posts]
end

Use Blocks For Adding Computed Fields

#app/admin/posts.rb
ActiveAdmin.register Post do
  config.xlsx_builder.column('author_name') do |resource|
    resource.author.name
  end
end

Change The Column Header Style

#app/admin/posts.rb
ActiveAdmin.register Post do
  config.xlsx_builder.header_style = { :bg_color => 'FF0000',
                                       :fg_color => 'FF' }
end

Remove Columns

#app/admin/posts.rb
ActiveAdmin.register Post do
  config.xlsx_builder.delete_columns :id, :created_at, :updated_at
end

Using the DSL

Everything that you do with the config'd 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, :axlsx, :post],
       :header_style => {:bg_color => 'FF0000', :fg_color => 'FF' }) 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|
      sheet.add_row []
      sheet.add_row ['Author Name', 'Number of Posts']
      data = []
      labels = []
      User.all.each do |user|
        data << user.posts.size
        labels << "#{user.first_name} #{user.last_name}"
        sheet.add_row [labels.last, data.last]
      end
      chart_color =  %w(88F700 279CAC B2A200 FD66A3 F20062 C8BA2B 67E6F8 DFFDB9 FFE800 B6F0F8)
      sheet.add_chart(::Axlsx::Pie3DChart, :title => "post by author") do |chart|
        chart.add_series :data => data, :labels => labels, :colors => chart_color
        chart.start_at 4, 0
        chart.end_at 7, 20
      end
    }

    # iserting data with before_filter
    before_filter do |sheet|
      sheet.add_row ['Created', Time.zone.now]
      sheet.add_row []
    end
  end
end

Specs


Running specs for this gem requires that you construct a rails application. To execute the specs, navigate to the gem directory, then run bundle install and run these two rake tasks:

bundle exec rake setup
bundle exec rake

Credits


Originally created by Randy Morgan - @randym

Forked in 2019, to enable the community to maintain the Axlsx ecosystem - http://github.com/caxlsx

Open source software is a community effort. None of this could have been done without the help of our Contributors.

activeadmin-caxlsx's People

Contributors

randym avatar noniq avatar westonganger avatar zevgeniy avatar straydogstudio avatar steveltn avatar zaychoer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.