Class: Axlsx::TableStyle

Inherits:
SimpleTypedList show all
Defined in:
lib/axlsx/stylesheet/table_style.rb

Overview

Note:

Table are not supported in this version and only the defaults required for a valid workbook are created.

A single table style definition and is a collection for tableStyleElements

Constant Summary

Constant Summary

Constants inherited from SimpleTypedList

SimpleTypedList::DELEGATES, SimpleTypedList::DESTRUCTIVE

Instance Attribute Summary (collapse)

Attributes inherited from SimpleTypedList

#allowed_types, #locked_at, #serialize_as

Instance Method Summary (collapse)

Methods inherited from SimpleTypedList

#<<, #==, #[]=, #delete, #delete_at, #lock, #protected?, #push, #to_ary, #to_xml, #unlock

Constructor Details

- (TableStyle) initialize(name, options = {})

creates a new TableStyle object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • pivot (Boolean)
  • table (Boolean)

Raises:

  • (ArgumentError)

    if name option is not provided.



24
25
26
27
28
29
30
# File 'lib/axlsx/stylesheet/table_style.rb', line 24

def initialize(name, options={})
  self.name = name
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
  end
  super TableStyleElement
end

Instance Attribute Details

- (string) name

The name of this table style

Returns:

  • (string)


9
10
11
# File 'lib/axlsx/stylesheet/table_style.rb', line 9

def name
  @name
end

- (Boolean) pivot

indicates if this style should be applied to pivot tables

Returns:

  • (Boolean)


13
14
15
# File 'lib/axlsx/stylesheet/table_style.rb', line 13

def pivot
  @pivot
end

- (Boolean) table

indicates if this style should be applied to tables

Returns:

  • (Boolean)


17
18
19
# File 'lib/axlsx/stylesheet/table_style.rb', line 17

def table
  @table
end

Instance Method Details

- (String) to_xml_string(str = '')

Serializes the object

Parameters:

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

Returns:

  • (String)


42
43
44
45
46
47
48
49
50
# File 'lib/axlsx/stylesheet/table_style.rb', line 42

def to_xml_string(str = '')
  attr = self.instance_values.select { |k, v| [:name, :pivot, :table].include? k }
  attr[:count] = self.size
  str << '<tableStyle '
  str << attr.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
  str << '>'
  each { |table_style_el| table_style_el.to_xml_string(str) }
  str << '</tableStyle>'
end