Class: Axlsx::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/table.rb

Overview

Note:

Worksheet#add_table is the recommended way to create tables for your worksheets.

Table

See Also:

  • for examples

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref, sheet, options = {}) {|_self| ... } ⇒ Table

Creates a new Table object

Parameters:

  • ref (String)

    The reference to the table data like 'A1:G24'.

  • sheet (Worksheet)

    The sheet containing the table data.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

Yields:

  • (_self)

Yield Parameters:

  • _self (Axlsx::Table)

    the object that the method was called on



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/axlsx/workbook/worksheet/table.rb', line 26

def initialize(ref, sheet, options={})
  @ref = ref
  @sheet = sheet
  @style = nil
  @sheet.workbook.tables << self
  @name = "Table#{index+1}"
  options.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

#nameString

The name of the table.

Returns:

  • (String)


15
16
17
# File 'lib/axlsx/workbook/worksheet/table.rb', line 15

def name
  @name
end

#refString (readonly)

The reference to the table data

Returns:

  • (String)


11
12
13
# File 'lib/axlsx/workbook/worksheet/table.rb', line 11

def ref
  @ref
end

#styleTableStyle (readonly)

The style for the table.

Returns:



19
20
21
# File 'lib/axlsx/workbook/worksheet/table.rb', line 19

def style
  @style
end

Instance Method Details

#indexInteger

The index of this chart in the workbooks charts collection

Returns:

  • (Integer)


40
41
42
# File 'lib/axlsx/workbook/worksheet/table.rb', line 40

def index
  @sheet.workbook.tables.index(self)
end

#pnString

The part name for this table

Returns:

  • (String)


46
47
48
# File 'lib/axlsx/workbook/worksheet/table.rb', line 46

def pn
  "#{TABLE_PN % (index+1)}"
end

#rIdString

The relation reference id for this table

Returns:

  • (String)


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

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


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