Class: GenericSpreadsheet

Inherits:
Object
  • Object
show all
Defined in:
lib/generic_spreadsheet.rb

Instance Method Summary collapse

Instance Method Details

#to_csv(filename = nil, sheet = nil) ⇒ Object

write the current spreadsheet to csv_string



4
5
6
# File 'lib/generic_spreadsheet.rb', line 4

def to_csv(filename=nil,sheet=nil)
  csv_string = write_csv_content(STDOUT,sheet)
end

#write_csv_content(file = nil, sheet = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generic_spreadsheet.rb', line 8

def write_csv_content(file=nil,sheet=nil)
 csv_string = ""
  if first_row(sheet) # sheet is not empty
    1.upto(last_row(sheet)) do |row|
      1.upto(last_column(sheet)) do |col|
        csv_string += "," if col > 1
        onecell = cell(row,col,sheet)
        onecelltype = celltype(row,col,sheet)
        csv_string += one_cell_output(onecelltype,onecell,empty?(row,col,sheet))
      end
      csv_string += "\n"
    end # sheet not empty
  end
  csv_string
end