Class: Axlsx::Table
- Inherits:
-
Object
- Object
- Axlsx::Table
- 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 relation reference id for this table.
-
#to_xml_string(str = '') ⇒ String
Serializes the object.
Constructor Details
#initialize(ref, sheet, options = {}) {|_self| ... } ⇒ Table
Creates a new Table object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 26 def initialize(ref, sheet, ={}) @ref = ref @sheet = sheet @style = nil @sheet.workbook.tables << self @name = "Table#{index+1}" .each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end yield self if block_given? end |
Instance Attribute Details
#name ⇒ String
The name of the table.
15 16 17 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 15 def name @name end |
#ref ⇒ String (readonly)
The reference to the table data
11 12 13 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 11 def ref @ref end |
#style ⇒ TableStyle (readonly)
The style for the table.
19 20 21 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 19 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 "#{TABLE_PN % (index+1)}" end |
#rId ⇒ String
The relation reference id for this table
52 53 54 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 52 def rId "rId#{index+1}" end |
#to_xml_string(str = '') ⇒ String
Serializes the object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/axlsx/workbook/worksheet/table.rb', line 69 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.value << '"/>' end str << '</tableColumns>' #TODO implement tableStyleInfo str << '<tableStyleInfo showFirstColumn="0" showLastColumn="0" showRowStripes="1" showColumnStripes="0" name="TableStyleMedium9" />' str << '</table>' end |