XlsReporter
XlsReporter lets you to export a collection of data to an Excel file, in a Ruby or Ruby on Rails project. Only need to specify the way to show data in the report.
Installation
Add this line to your application's Gemfile:
gem 'xls_reporter'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install xls_reporter
Usage
To export data:
table_reporter = XlsReporter::DataExport.new
table_reporter.generate_excel(collection, header_params, body_params,
filename, filepath, batch_iteration, retry_methods)
with the follow parameters:
- collection: set of iterable data (
ActiveRecord::Relation
, Array
of objects, etc.). - header_params:
Array
of hashes, indicate the title of each column:
header_params = [
{:index => 0, :title => "SKU"},
{:index => 1, :title => "Event"},
{:index => 2, :title => I18n.t(model.attribute)},
]
- body_params:
Array
of hashes, indicate the methods (and their params) to apply in each element of collection to show in report:
body_params = [
{:index => 0, :object_methods => :get_sku },
{:index => 1, :object_methods => {:get_event => Time.now } },
{:index => 2, :object_methods => [
{:method_name=>:values_by_ids, :params_values => [1,2,4]},
:get_color ,
{:method_name =>:set_size, :params_values => "large"}
]
},
]
- filename:
String
with the name of the exported file (ie: report.xlsx). - filepath:
String
with the path for save the report file. - batch_iteration: this
boolean
option permit iterate data in batches if you use ActiveRecord
. Default is true. - retry_methods: this
boolean
option is used to manage exceptions when calling methods in data elements, and retry them. Default is true.
TO DO
Write tests and validate code.
Contributing
- Fork it ( https://github.com/[my-github-username]/xls_reporter/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request