Sha256: 93e14a56b41a1f79147d9575b382570995105d89a4739b999c4b70d3c697002b
Contents?: true
Size: 1.03 KB
Versions: 12
Compression:
Stored size: 1.03 KB
Contents
# -*- encoding : utf-8 -*- require 'csv' module Workbook module Writers module CsvTableWriter # Output the current workbook to CSV format # # @param [String] filename # @param [Hash] options (not used) # @return [String] csv (comma separated values in a string) def to_csv options={} csv = "" options = {}.merge options self.each_with_index do |r, ri| line=nil begin line = CSV::generate_line(r.collect{|c| c.value if c},{:row_sep=>""}) rescue TypeError line = CSV::generate_line(r.collect{|c| c.value if c}) end csv += "#{line}\n" end csv end # Write the current workbook to CSV format # # @param [String] filename # @param [Hash] options see #to_csv # @return [String] filename def write_to_csv filename="#{title}.csv", options={} File.open(filename, 'w') {|f| f.write(to_csv(options)) } return filename end end end end
Version data entries
12 entries across 12 versions & 1 rubygems