ActiveWorksheet

Work with local and remote worksheets like ActiveRecord/ActiveResource models.


gem install active_worksheet

View on Github

Demo

What does it do?

ActiveWorksheet reads local spreadsheet files (XLS, XLSX and CSV) and presents them as ActiveRecord/ActiveResource objects, mapping rows as records and columns and attributes.

Installation

Add this line to your application's Gemfile:

gem 'active_worksheet'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_worksheet

Usage

Having the following CSV file:

id,first_name,last_name,email,company
1,Brendis,MacCahee,bmaccahee0@privacy.gov.au,Klocko and Sons
2,Abbe,John,ajohn1@ibm.com,"Mayer, Weimann and Stark"
3,Buffy,Schiersch,bschiersch2@chronoengine.com,"Gusikowski, Schmidt and Watsica"
4,Flore,Aberhart,faberhart3@boston.com,Beatty Group

It can be represented as an object using active_worksheet:

class ImportedAccount < ActiveWorksheet::Base
self.source = "./accounts.csv"
end

The ImportedAccount class will read the file as a spreadsheet and treat the first row as the collection's headers, where each column is an attribute name.

ImportedAccount.count
# => 4

ImportedAccount.first
# => #<ImportedAccount id=1, first_name="Brendis", last_name="MacCahee", email="bmaccahee0@privacy.gov.au", company="Klocko and Sons">