Class: Spreet::Handlers::ExcelCSV
- Defined in:
- lib/spreet/handlers/excel_csv.rb
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 17 |
# File 'lib/spreet/handlers/excel_csv.rb', line 9 def self.read(file, ={}) spreet = Spreet::Document.new sheet = spreet.sheets.add = {:col_sep=>';', :encoding => "CP1252"}.merge() ::CSV.foreach(file, ) do |row| sheet.row *(row.map{|v| v.to_s.encode('utf-8')}) # collect{|v| v.to_s.encode('cp1252')} end return spreet end |
.write(spreet, file, options = {}) ⇒ Object
Write a Spreet to a CSV file
21 22 23 24 25 26 27 28 29 |
# File 'lib/spreet/handlers/excel_csv.rb', line 21 def self.write(spreet, file, ={}) sheet = spreet.sheets[[:sheet]||0] = {:col_sep=>';', :encoding => "CP1252"}.merge() ::CSV.open(file, "wb", ) do |csv| sheet.each_row do |row| csv << row.map(&:text) end end end |