Class: OoxmlParser::Xf

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb

Overview

Class for parsing ‘xf` object

Constant Summary collapse

ALL_FORMAT_VALUE =
Array<String,nil>

list of predefined format values

['General',
'0',
'0.00',
'#,##0',
'#,##0.00',
'$#,##0_);($#,##0)',
'$#,##0_);[Red]($#,##0)',
'$#,##0.00_);($#,##0.00)',
'$#,##0.00_);[Red]($#,##0.00)',
'0%', '0.00%',
'0.00E+00',
'# ?/?',
'# ??/??',
'm/d/yyyy',
'd-mmm-yy',
'd-mmm',
'mmm-yy',
'h:mm AM/PM',
'h:mm:ss AM/PM',
'h:mm',
'h:mm:ss',
'm/d/yyyy h:mm',
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
nil,
'#,##0_);(#,##0)',
'#,##0_);[Red](#,##0)',
'#,##0.00_);(#,##0.00)',
'#,##0.00_);[Red](#,##0.00)',
nil,
nil,
nil,
nil,
'mm:ss',
'[h]:mm:ss',
'mm:ss.0',
'##0.0E+0',
'@'].freeze

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ Xf

Returns a new instance of Xf.



83
84
85
86
87
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 83

def initialize(parent: nil)
  @numerical_format = 'General'
  @alignment = XlsxAlignment.new
  super
end

Instance Attribute Details

#alignmentObject (readonly)

Returns the value of attribute alignment.



59
60
61
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 59

def alignment
  @alignment
end

#apply_alignmentTrue, False (readonly)

Returns is alignment applied.

Returns:

  • (True, False)

    is alignment applied



71
72
73
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 71

def apply_alignment
  @apply_alignment
end

#apply_borderTrue, False (readonly)

Returns is border applied.

Returns:

  • (True, False)

    is border applied



65
66
67
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 65

def apply_border
  @apply_border
end

#apply_fillTrue, False (readonly)

Returns is fill applied.

Returns:

  • (True, False)

    is fill applied



67
68
69
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 67

def apply_fill
  @apply_fill
end

#apply_fontTrue, False (readonly)

Returns is font applied.

Returns:

  • (True, False)

    is font applied



63
64
65
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 63

def apply_font
  @apply_font
end

#apply_number_formatTrue, False (readonly)

Returns is number format applied.

Returns:

  • (True, False)

    is number format applied



69
70
71
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 69

def apply_number_format
  @apply_number_format
end

#border_idInteger (readonly)

Returns id of border.

Returns:

  • (Integer)

    id of border



75
76
77
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 75

def border_id
  @border_id
end

#fill_idInteger (readonly)

Returns id of fill.

Returns:

  • (Integer)

    id of fill



77
78
79
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 77

def fill_id
  @fill_id
end

#font_idInteger (readonly)

Returns id of font.

Returns:

  • (Integer)

    id of font



73
74
75
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 73

def font_id
  @font_id
end

#number_format_idInteger (readonly)

Returns id of number format.

Returns:

  • (Integer)

    id of number format



79
80
81
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 79

def number_format_id
  @number_format_id
end

#protectionProtection (readonly)

Returns Settings of cell protection.

Returns:



81
82
83
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 81

def protection
  @protection
end

#quote_prefixTrue, False (readonly)

Returns check if style should add QuotePrefix (‘ symbol) to start of the string.

Returns:

  • (True, False)

    check if style should add QuotePrefix (‘ symbol) to start of the string



61
62
63
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 61

def quote_prefix
  @quote_prefix
end

Instance Method Details

#bordersXlsxBorder

Returns border of object.

Returns:



134
135
136
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 134

def borders
  root_object.style_sheet.borders.borders_array[@border_id] if @apply_border
end

#fill_colorFill

Returns fill color of object.

Returns:

  • (Fill)

    fill color of object



139
140
141
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 139

def fill_color
  root_object.style_sheet.fills[@fill_id] if @apply_fill
end

#fontFont

Returns font of object.

Returns:

  • (Font)

    font of object



129
130
131
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 129

def font
  root_object.style_sheet.fonts[@font_id]
end

#numerical_formatString

Returns numerical format of object.

Returns:

  • (String)

    numerical format of object



144
145
146
147
148
149
150
151
152
153
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 144

def numerical_format
  return @numerical_format unless @apply_number_format

  format = root_object.style_sheet.number_formats.format_by_id(@number_format_id)
  if format
    format.format_code
  else
    ALL_FORMAT_VALUE[@number_format_id]
  end
end

#parse(node) ⇒ Xf

Parse Xf object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:

  • (Xf)

    result of parsing



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 92

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'applyFont'
      @apply_font = boolean_attribute_value(value)
    when 'applyBorder'
      @apply_border = boolean_attribute_value(value)
    when 'applyFill'
      @apply_fill = boolean_attribute_value(value)
    when 'applyNumberFormat'
      @apply_number_format = boolean_attribute_value(value)
    when 'applyAlignment'
      @apply_alignment = boolean_attribute_value(value)
    when 'fontId'
      @font_id = value.value.to_i
    when 'borderId'
      @border_id = value.value.to_i
    when 'fillId'
      @fill_id = value.value.to_i
    when 'numFmtId'
      @number_format_id = value.value.to_i
    when 'quotePrefix'
      @quote_prefix = attribute_enabled?(value)
    end
  end
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'alignment'
      @alignment.parse(node_child) if @apply_alignment
    when 'protection'
      @protection = Protection.new(parent: self).parse(node_child)
    end
  end
  self
end