Class: Tableview::Output::XLS

Inherits:
Object
  • Object
show all
Defined in:
lib/tableview/output/xls.rb

Constant Summary collapse

HEADER_STYLE =
{:align => :center, :weight => :bold}
{:weight => :bold }

Instance Method Summary collapse

Instance Method Details

#process(tv) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tableview/output/xls.rb', line 7

def process(tv)
  
  @table = Spreadsheet::Workbook.new
  tv.subtables.each do |sub|
    sheet1 = @table.create_worksheet :name => sub.title
    offset = 0
    sub.parts.each do |part|
      p_style = case part.class.to_s
      when "Tableview::ViewHandler::Header"
        HEADER_STYLE.dup
      when "Tableview::ViewHandler::Footer"
        FOOTER_STYLE.dup
      else
        {}
      end.merge part.options
    
      part.rows.each do |row|
        style = p_style.merge row.options
        row.cells.each_with_index do |cell, i|
          format = Spreadsheet::Format.new style.merge(cell.options)
          sheet1[offset, i] = cell.contents
          sheet1.row(offset).set_format i, format
        end
        offset += 1
      end
    end
  end
end

#to_sObject



36
37
38
39
40
41
# File 'lib/tableview/output/xls.rb', line 36

def to_s
  io = StringIO.new
  @table.write(io)
  io.rewind
  string = io.read
end