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,firstname.lastname@example.org,Klocko and Sons 2,Abbe,John,email@example.com,"Mayer, Weimann and Stark" 3,Buffy,Schiersch,firstname.lastname@example.org,"Gusikowski, Schmidt and Watsica" 4,Flore,Aberhart,email@example.com,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="firstname.lastname@example.org", company="Klocko and Sons">