No commit activity in last 3 years
No release in over 3 years
This simple plugin gives you the ability to get XLS for a collection of ActiveRecord models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 3.7.0, ~> 3.7

Runtime

~> 0.8.5
 Project Readme

ActiveRecordToXls

This gem will generate XLS data for a collection of ActiveRecord models.

It was forked from the to_xls-rails gem.

Installation

Gemfile:

gem 'active_record_to_xls'

config/initializers/mime_types.rb:

Mime::Type.register_alias "text/excel", :xls

Usage

controller:

format.xls {
  filename = “my_export.xls”
  send_data ActiveRecordToXls.call(Widget.all)
}

view:

link_to 'Export Excel', my_action_path(format: :xls)

Options

client_encoding

  • Type: String
  • Default: UTF-8

only

  • Type: Array

Will only include the columns specified in this array:

send_data ActiveRecordToXls.call( Widget.all, only: [:title, :body] )

except

  • Type: Array

Will omit the columns specified in this array, eg:

send_data ActiveRecordToXls.call( Widget.all, omit: [:id] )

prepend

  • Type: Array of row arrays

Will prepend above header:

send_data ActiveRecordToXls.call( Widget.all, prepend: [["Col 0, Row 0", "Col 1, Row 0"], ["Col 0, Row 1"]] )

header

  • Type: true or false
  • Default: false

Will omit the header row:

send_data ActiveRecordToXls.call( Widget.all, header: false )

header_columns

  • Type: Array

Specify header column names:

send_data ActiveRecordToXls.call( Widget.all, header: false , header_columns: ['Title', 'Description])

column_width

  • Type: Array of integers

Set column widths:

send_data ActiveRecordToXls.call( Widget.all, column_width: [17,15,15,40,25,37] )

append

  • Type: Array of row arrays

Will append this row at end, eg:

send_data ActiveRecordToXls.call( Widget.all, append: [["Col 0, Row 0", "Col 1, Row 0"], ["Col 0, Row 1"]] )