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.
Add this line to your application's Gemfile:
gem 'active_worksheet'And then execute:
$ bundleOr install it yourself as:
$ gem install active_worksheet
Having the following CSV file:
id,first_name,last_name,email,company 1,Brendis,MacCahee,email@example.com,Klocko and Sons 2,Abbe,John,firstname.lastname@example.org,"Mayer, Weimann and Stark" 3,Buffy,Schiersch,email@example.com,"Gusikowski, Schmidt and Watsica" 4,Flore,Aberhart,firstname.lastname@example.org,Beatty Group
It can be represented as an object using
class ImportedAccount < ActiveWorksheet::Baseself.source = "./accounts.csv"end
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# => 4ImportedAccount.first# => #<ImportedAccount id=1, first_name="Brendis", last_name="MacCahee", email="email@example.com", company="Klocko and Sons">