Class: TableSetting::Stack

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStack

Returns a new instance of Stack.



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

def initialize
  @sheets = []
end

Instance Attribute Details

#sheetsObject

Returns the value of attribute sheets.



2
3
4
# File 'lib/table_setting/stack.rb', line 2

def sheets
  @sheets
end

Instance Method Details

#cellsObject



8
9
10
11
12
13
14
# File 'lib/table_setting/stack.rb', line 8

def cells
  list = []
  sheets.each do |sheet|
    list += sheet.cells
  end
  list
end

#new_sheet(options = {}) ⇒ Object



17
18
19
# File 'lib/table_setting/stack.rb', line 17

def new_sheet(options = {})
  TableSetting::Sheet.new(self, options)
end

#to_xlsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/table_setting/stack.rb', line 21

def to_xls
  xml = <<-XML
    <?xml version="1.0"?>
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
      xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:x="urn:schemas-microsoft-com:office:excel"
      xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
      xmlns:html="http://www.w3.org/TR/REC-html40">
      <Styles>
      #{xls_styles}
      </Styles>
      #{sheets.map{|s| s.to_xls(true)}.join}
    </Workbook>
  XML
  xml.strip!
end

#xls_stylesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/table_setting/stack.rb', line 39

def xls_styles
  signatures = {}
  cells.each do |cell|
    next if signatures[cell.style_name]
    signatures[cell.style_name] = cell.style_xls
  end

  xml = ''
  signatures.each do |signature_class, signature_xls_style|
    xml += <<-XML
      <Style ss:ID="#{signature_class}">
        #{signature_xls_style}
      </Style>
    XML
  end
  xml
end