Class: OoxmlParser::CellStyle
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::CellStyle
- Defined in:
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb
Overview
Class for parsing cell style
Constant Summary collapse
- ALL_FORMAT_VALUE =
%w|0 0.00 #,##0 #,##0.00 $#,##0_);($#,##0) $#,##0_);[Red]($#,##0) $#,##0.00_);($#,##0.00) $#,##0.00_);[Red]($#,##0.00) 0.00% 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #,##0_);(#,##0) #,##0_);[Red](#,##0) #,##0.00_);(#,##0.00) #,##0.00_);[Red](#,##0.00) 0 0 0 0 mm:ss General mm:ss.0 ##0.0E+0 @|.freeze
Instance Attribute Summary collapse
-
#alignment ⇒ Object
Returns the value of attribute alignment.
-
#apply_alignment ⇒ True, False
Is alignment applied.
-
#apply_border ⇒ True, False
Is border applied.
-
#apply_fill ⇒ True, False
Is fill applied.
-
#apply_font ⇒ True, False
Is font applied.
-
#apply_number_format ⇒ True, False
Is number format applied.
-
#border_id ⇒ Integer
Id of border.
-
#borders ⇒ Object
Returns the value of attribute borders.
-
#fill_color ⇒ Object
Returns the value of attribute fill_color.
-
#fill_id ⇒ Integer
Id of fill.
-
#font ⇒ Object
Returns the value of attribute font.
-
#font_id ⇒ Integer
Id of font.
-
#number_format_id ⇒ Integer
Id of number format.
-
#numerical_format ⇒ Object
Returns the value of attribute numerical_format.
-
#quote_prefix ⇒ True, False
Check if style should add QuotePrefix (‘ symbol) to start of the string.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
- #calculate_values ⇒ Object
-
#initialize(parent: nil) ⇒ CellStyle
constructor
A new instance of CellStyle.
-
#parse(node) ⇒ CellStyle
Parse CellStyle object.
Methods inherited from OOXMLDocumentObject
#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(parent: nil) ⇒ CellStyle
Returns a new instance of CellStyle.
70 71 72 73 74 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 70 def initialize(parent: nil) @numerical_format = 'General' @alignment = XlsxAlignment.new @parent = parent end |
Instance Attribute Details
#alignment ⇒ Object
Returns the value of attribute alignment.
48 49 50 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 48 def alignment @alignment end |
#apply_alignment ⇒ True, False
Returns is alignment applied.
60 61 62 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 60 def apply_alignment @apply_alignment end |
#apply_border ⇒ True, False
Returns is border applied.
54 55 56 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 54 def apply_border @apply_border end |
#apply_fill ⇒ True, False
Returns is fill applied.
56 57 58 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 56 def apply_fill @apply_fill end |
#apply_font ⇒ True, False
Returns is font applied.
52 53 54 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 52 def apply_font @apply_font end |
#apply_number_format ⇒ True, False
Returns is number format applied.
58 59 60 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 58 def apply_number_format @apply_number_format end |
#border_id ⇒ Integer
Returns id of border.
64 65 66 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 64 def border_id @border_id end |
#borders ⇒ Object
Returns the value of attribute borders.
48 49 50 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 48 def borders @borders end |
#fill_color ⇒ Object
Returns the value of attribute fill_color.
48 49 50 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 48 def fill_color @fill_color end |
#fill_id ⇒ Integer
Returns id of fill.
66 67 68 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 66 def fill_id @fill_id end |
#font ⇒ Object
Returns the value of attribute font.
48 49 50 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 48 def font @font end |
#font_id ⇒ Integer
Returns id of font.
62 63 64 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 62 def font_id @font_id end |
#number_format_id ⇒ Integer
Returns id of number format.
68 69 70 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 68 def number_format_id @number_format_id end |
#numerical_format ⇒ Object
Returns the value of attribute numerical_format.
48 49 50 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 48 def numerical_format @numerical_format end |
#quote_prefix ⇒ True, False
Returns check if style should add QuotePrefix (‘ symbol) to start of the string.
50 51 52 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 50 def quote_prefix @quote_prefix end |
Instance Method Details
#calculate_values ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 115 def calculate_values @font = root_object.style_sheet.fonts[@font_id] @borders = Borders.parse_from_style(@border_id) if @apply_border @fill_color = root_object.style_sheet.fills[@fill_id] if @apply_fill return unless @apply_number_format format = root_object.style_sheet.number_formats.format_by_id(@number_format_id) @numerical_format = if format format.format_code else CellStyle::ALL_FORMAT_VALUE[@number_format_id - 1] end end |
#parse(node) ⇒ CellStyle
Parse CellStyle object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style.rb', line 79 def parse(node) style_node = XLSXWorkbook.styles_node.xpath('//xmlns:cellXfs/xmlns:xf')[node.to_i] style_node.attributes.each do |key, value| case key when 'applyFont' @apply_font = attribute_enabled?(value) when 'applyBorder' @apply_border = attribute_enabled?(value) when 'applyFill' @apply_fill = attribute_enabled?(value) when 'applyNumberFormat' @apply_number_format = attribute_enabled?(value) when 'applyAlignment' @apply_alignment = attribute_enabled?(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 style_node.xpath('*').each do |node_child| case node_child.name when 'alignment' @alignment.parse(node_child) if @apply_alignment end end calculate_values self end |