Class: Spreet::Handlers::CSV
Class Method Summary collapse
-
.read(file, options = {}) ⇒ Object
Read a CSV file and create its Spreet document.
-
.write(spreet, file, options = {}) ⇒ Object
Write a Spreet to a CSV file.
Class Method Details
.read(file, options = {}) ⇒ Object
Read a CSV file and create its Spreet document
9 10 11 12 13 14 15 16 |
# File 'lib/spreet/handlers/csv.rb', line 9 def self.read(file, ={}) spreet = Spreet::Document.new sheet = spreet.sheets.add ::CSV.foreach(file) do |row| sheet.row *row end return spreet end |
.write(spreet, file, options = {}) ⇒ Object
Write a Spreet to a CSV file
20 21 22 23 24 25 26 27 |
# File 'lib/spreet/handlers/csv.rb', line 20 def self.write(spreet, file, ={}) sheet = spreet.sheets[[:sheet]||0] ::CSV.open(file, "wb") do |csv| sheet.each_row do |row| csv << row.collect{|c| c.text} end end end |