Class: OoxmlParser::Xf
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Xf
- 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
-
#alignment ⇒ Object
readonly
Returns the value of attribute alignment.
-
#apply_alignment ⇒ True, False
readonly
Is alignment applied.
-
#apply_border ⇒ True, False
readonly
Is border applied.
-
#apply_fill ⇒ True, False
readonly
Is fill applied.
-
#apply_font ⇒ True, False
readonly
Is font applied.
-
#apply_number_format ⇒ True, False
readonly
Is number format applied.
-
#border_id ⇒ Integer
readonly
Id of border.
-
#fill_id ⇒ Integer
readonly
Id of fill.
-
#font_id ⇒ Integer
readonly
Id of font.
-
#number_format_id ⇒ Integer
readonly
Id of number format.
-
#protection ⇒ Protection
readonly
Settings of cell protection.
-
#quote_prefix ⇒ True, False
readonly
Check if style should add QuotePrefix (‘ symbol) to start of the string.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#borders ⇒ XlsxBorder
Border of object.
-
#fill_color ⇒ Fill
Fill color of object.
-
#font ⇒ Font
Font of object.
-
#initialize(parent: nil) ⇒ Xf
constructor
A new instance of Xf.
-
#numerical_format ⇒ String
Numerical format of object.
-
#parse(node) ⇒ Xf
Parse Xf object.
Methods inherited from OOXMLDocumentObject
#==, #boolean_attribute_value, #parse_xml, #with_data?
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
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
#alignment ⇒ Object (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_alignment ⇒ True, False (readonly)
Returns 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_border ⇒ True, False (readonly)
Returns 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_fill ⇒ True, False (readonly)
Returns 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_font ⇒ True, False (readonly)
Returns 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_format ⇒ True, False (readonly)
Returns 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_id ⇒ Integer (readonly)
Returns 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_id ⇒ Integer (readonly)
Returns 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_id ⇒ Integer (readonly)
Returns 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_id ⇒ Integer (readonly)
Returns 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 |
#protection ⇒ Protection (readonly)
Returns Settings of cell protection.
81 82 83 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/cell_xfs/xf.rb', line 81 def protection @protection end |
#quote_prefix ⇒ True, False (readonly)
Returns 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
#borders ⇒ XlsxBorder
Returns border of object.
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_color ⇒ Fill
Returns 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 |
#font ⇒ Font
Returns 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_format ⇒ String
Returns 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
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 |