Class: OpenXml::Xlsx::Parts::Table

Inherits:
Part
  • Object
show all
Defined in:
lib/openxml/xlsx/parts/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, ref, columns) ⇒ Table

Returns a new instance of Table.



7
8
9
10
11
12
# File 'lib/openxml/xlsx/parts/table.rb', line 7

def initialize(id, name, ref, columns)
  @id = id
  @name = name
  @ref = ref
  @columns = columns
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



5
6
7
# File 'lib/openxml/xlsx/parts/table.rb', line 5

def columns
  @columns
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/openxml/xlsx/parts/table.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/openxml/xlsx/parts/table.rb', line 5

def name
  @name
end

#refObject (readonly)

Returns the value of attribute ref.



5
6
7
# File 'lib/openxml/xlsx/parts/table.rb', line 5

def ref
  @ref
end

Instance Method Details

#filenameObject



14
15
16
# File 'lib/openxml/xlsx/parts/table.rb', line 14

def filename
  "table#{id}.xml"
end

#to_xmlObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/openxml/xlsx/parts/table.rb', line 18

def to_xml
  build_standalone_xml do |xml|
    xml.table(xmlns: "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
      id: id, name: name, displayName: name, ref: ref, totalsRowShown: 0) do
      xml.autoFilter ref: ref
      xml.tableColumns(count: columns.length) do
        columns.each_with_index do |column, index|
          xml.tableColumn(id: index + 1, name: column.name)
        end
      end
      xml.tableStyleInfo(name: "TableStyleLight6", showFirstColumn: 0, showLastColumn: 0, showRowStripes: 1, showColumnStripes: 0)
    end
  end
end