Class: TableData::Presenters::Excel

Inherits:
TableData::Presenter show all
Defined in:
lib/tabledata/presenters/excel.rb

Constant Summary collapse

Bold =
Spreadsheet::Format.new weight: :bold

Instance Attribute Summary

Attributes inherited from TableData::Presenter

#table

Instance Method Summary collapse

Methods inherited from TableData::Presenter

#initialize, present

Constructor Details

This class inherits a constructor from TableData::Presenter

Instance Method Details

#documentObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tabledata/presenters/excel.rb', line 13

def document
  document          = Spreadsheet::Workbook.new
  sheet             = document.create_worksheet(name: @options[:worksheet_name])
  sheet.row(0).default_format = Bold if @options[:bold_headers]

  @table.data.each_with_index do |row, row_nr|
    row.each_with_index do |col, col_nr|
      sheet[row_nr, col_nr] = col
    end
  end

  document
end

#string(options = nil) ⇒ Object



27
28
29
# File 'lib/tabledata/presenters/excel.rb', line 27

def string(options=nil)
  document.to_string
end

#write(path, options = nil) ⇒ Object



31
32
33
# File 'lib/tabledata/presenters/excel.rb', line 31

def write(path, options=nil)
  document.write(path)
end