module Workbook::Writers::CsvTableWriter

Public Instance Methods

to_csv(options={}) click to toggle source

Output the current workbook to CSV format

@param [Hash] options (not used) @return [String] csv (comma separated values in a string)

# File lib/workbook/writers/csv_table_writer.rb, line 14
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_to_csv(filename=" click to toggle source

Write the current workbook to CSV format

@param [String] filename @param [Hash] options see to_csv @return [String] filename

# File lib/workbook/writers/csv_table_writer.rb, line 34
def write_to_csv filename="#{title}.csv", options={}
  File.open(filename, 'w') {|f| f.write(to_csv(options)) }
  return filename
end