Class: Axlsx::Table
- Inherits:
-
Object
- Object
- Axlsx::Table
- Includes:
- OptionsParser
- Defined in:
- lib/axlsx/workbook/worksheet/table.rb
Overview
Note:
Worksheet#add_table is the recommended way to create tables for your worksheets.
Table
Instance Attribute Summary collapse
-
#name ⇒ String
The name of the table.
-
#ref ⇒ String
readonly
The reference to the table data.
-
#style ⇒ TableStyle
readonly
The style for the table.
Instance Method Summary collapse
-
#index ⇒ Integer
The index of this chart in the workbooks charts collection.
-
#initialize(ref, sheet, options = {}) {|_self| ... } ⇒ Table
constructor
Creates a new Table object.
-
#pn ⇒ String
The part name for this table.
-
#rId ⇒ String
The relationship id for this table.
-
#table_style_info ⇒ Object
TableStyleInfo for the table.
-
#to_xml_string(str = +'')) ⇒ String
Serializes the object.
Methods included from OptionsParser
Constructor Details
#initialize(ref, sheet, options = {}) {|_self| ... } ⇒ Table
Creates a new Table object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 15 def initialize(ref, sheet, = {}) @ref = ref @sheet = sheet @style = nil @sheet.workbook.tables << self @table_style_info = TableStyleInfo.new([:style_info]) if [:style_info] @name = "Table#{index + 1}" yield self if block_given? end |
Instance Attribute Details
#name ⇒ String
The name of the table.
32 33 34 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 32 def name @name end |
#ref ⇒ String (readonly)
The reference to the table data
28 29 30 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 28 def ref @ref end |
#style ⇒ TableStyle (readonly)
The style for the table.
36 37 38 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 36 def style @style end |
Instance Method Details
#index ⇒ Integer
The index of this chart in the workbooks charts collection
40 41 42 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 40 def index @sheet.workbook.tables.index(self) end |
#pn ⇒ String
The part name for this table
46 47 48 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 46 def pn format(TABLE_PN, index + 1) end |
#rId ⇒ String
The relationship id for this table.
53 54 55 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 53 def rId @sheet.relationships.for(self).Id end |
#table_style_info ⇒ Object
TableStyleInfo for the table. initialization can be fed via the :style_info option
69 70 71 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 69 def table_style_info @table_style_info ||= TableStyleInfo.new end |
#to_xml_string(str = +'')) ⇒ String
Serializes the object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 76 def to_xml_string(str = +'') str << '<?xml version="1.0" encoding="UTF-8"?>' str << '<table xmlns="' << XML_NS << '" id="' << (index + 1).to_s << '" name="' << @name << '" displayName="' << @name.gsub(/\s/, '_') << '" ' str << 'ref="' << @ref << '" totalsRowShown="0">' str << '<autoFilter ref="' << @ref << '"/>' str << '<tableColumns count="' << header_cells.length.to_s << '">' header_cells.each_with_index do |cell, index| str << '<tableColumn id ="' << (index + 1).to_s << '" name="' << cell.clean_value << '"/>' end str << '</tableColumns>' table_style_info.to_xml_string(str) str << '</table>' end |