Class: OpenXml::Xlsx::Elements::Style

Inherits:
Struct
  • Object
show all
Defined in:
lib/openxml/xlsx/elements/style.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format_id = 0, font_id = 0, fill_id = 0, border_id = 0, alignment = nil) ⇒ Style

Returns a new instance of Style.



6
7
8
# File 'lib/openxml/xlsx/elements/style.rb', line 6

def initialize(format_id=0, font_id=0, fill_id=0, border_id=0, alignment=nil)
  super format_id || 0, font_id || 0, fill_id || 0, border_id || 0, alignment
end

Instance Attribute Details

#alignmentObject

Returns the value of attribute alignment

Returns:

  • (Object)

    the current value of alignment



4
5
6
# File 'lib/openxml/xlsx/elements/style.rb', line 4

def alignment
  @alignment
end

#border_idObject

Returns the value of attribute border_id

Returns:

  • (Object)

    the current value of border_id



4
5
6
# File 'lib/openxml/xlsx/elements/style.rb', line 4

def border_id
  @border_id
end

#fill_idObject

Returns the value of attribute fill_id

Returns:

  • (Object)

    the current value of fill_id



4
5
6
# File 'lib/openxml/xlsx/elements/style.rb', line 4

def fill_id
  @fill_id
end

#font_idObject

Returns the value of attribute font_id

Returns:

  • (Object)

    the current value of font_id



4
5
6
# File 'lib/openxml/xlsx/elements/style.rb', line 4

def font_id
  @font_id
end

#format_idObject

Returns the value of attribute format_id

Returns:

  • (Object)

    the current value of format_id



4
5
6
# File 'lib/openxml/xlsx/elements/style.rb', line 4

def format_id
  @format_id
end

Instance Method Details

#to_xml(xml) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/openxml/xlsx/elements/style.rb', line 10

def to_xml(xml)
  attributes = {
    numFmtId: format_id,
    fontId: font_id,
    fillId: fill_id,
    borderId: border_id }
  attributes.merge!(applyNumberFormat: 1) if format_id > 0
  attributes.merge!(applyFont: 1) if font_id > 0
  attributes.merge!(applyFill: 1) if fill_id > 0
  attributes.merge!(applyBorder: 1) if border_id > 0
  attributes.merge!(applyAlignment: 1) if alignment
  xml.xf(attributes) do
    alignment.to_xml(xml) if alignment
  end
end