ooxml_parser 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +6 -6
  3. data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +2 -0
  4. data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb +2 -2
  5. data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +5 -5
  6. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +1 -1
  7. data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +1 -1
  8. data/lib/ooxml_parser/version.rb +1 -1
  9. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/defined_name.rb +33 -0
  10. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/differential_formatting_records.rb +41 -0
  11. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet.rb +5 -0
  12. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/color_scale.rb +32 -0
  13. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/data_bar/conditional_format_value_object.rb +44 -0
  14. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/data_bar.rb +102 -0
  15. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/differential_formatting_record.rb +34 -0
  16. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/icon_set/conditional_formatting_icon.rb +26 -0
  17. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/icon_set.rb +55 -0
  18. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule.rb +100 -0
  19. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting.rb +32 -0
  20. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings.rb +33 -0
  21. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension.rb +5 -0
  22. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer/header_footer_child.rb +56 -0
  23. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer.rb +64 -0
  24. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +10 -0
  25. data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +12 -0
  26. metadata +16 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8d43b880b2291d11e75cf1107c546077d36d4123044cf71d0b85a5f7a62487b
4
- data.tar.gz: 6690b7dad0c09b17ac772af66a6f614a8e68331c6ddb247597cf818887e4b16e
3
+ metadata.gz: 0d95158b66da173b7cc2b1c80b4780c0893cb840ff47a20bee389285054e3f4e
4
+ data.tar.gz: ec88614112d6ec0c69e5269dd8d128ead722cd1d338ac0500f7868409e8a5160
5
5
  SHA512:
6
- metadata.gz: c6c51d4331048c7250d9724da8c00354d235df4dbe8fad57cc81783133a4d0a030ce02056000afb4a5f5d13a91e4f8f28ce51d82f4d581b55da6902fe2927f1a
7
- data.tar.gz: abc21e3b8151d29985cdb96a05e60eef69feb949fc6b12f24c225ba050d08ad021de39745250dbdef4920965dcca430473d0b3f089c4ca122ea790a612026ecc
6
+ metadata.gz: ac0bae842196c698f38563be771715d3cb78de1081904528f4557fe6faf0c7b20199945f0b5da952da0eef238e5b38a80e06e3c65a64a76b44824d9a105a24b4
7
+ data.tar.gz: cec21fd072fc64cc6ec436b86a0f68a0a11fb42356ca6826f20e2e8ccaa3de291e2ba2e8f76bcda5243473a46217f1d3a6b04beedfa0e9b2ac00f11aa9a7983f
@@ -53,12 +53,12 @@ module OoxmlParser
53
53
  @grouping = chart_props_node_child.attribute('val').value.to_sym
54
54
  when 'ser'
55
55
  @series << Series.new(parent: self).parse(chart_props_node_child)
56
- case @type
57
- when :point, :bubble
58
- val = chart_props_node_child.xpath('c:yVal')[0]
59
- else
60
- val = chart_props_node_child.xpath('c:val')[0]
61
- end
56
+ val = case @type
57
+ when :point, :bubble
58
+ chart_props_node_child.xpath('c:yVal')[0]
59
+ else
60
+ chart_props_node_child.xpath('c:val')[0]
61
+ end
62
62
  next unless val
63
63
  next if val.xpath('c:numRef').empty?
64
64
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'uri'
4
+
3
5
  module OoxmlParser
4
6
  # Class for storing image data
5
7
  class FileReference < OOXMLDocumentObject
@@ -23,8 +23,8 @@ module OoxmlParser
23
23
  # @return [String] text representation
24
24
  def to_s
25
25
  "Value: `#{value}`, "\
26
- "Color: `#{color}`, "\
27
- "Fill: `#{fill}`"
26
+ "Color: `#{color}`, "\
27
+ "Fill: `#{fill}`"
28
28
  end
29
29
 
30
30
  # Parse Shade
@@ -9,11 +9,11 @@ module OoxmlParser
9
9
  # @return [String] result of convert of object to string
10
10
  def to_s
11
11
  "Table position left: #{left}, "\
12
- "right: #{right}, "\
13
- "top: #{top}, "\
14
- "bottom #{bottom}, "\
15
- "position x: #{position_x}, "\
16
- "position y: #{position_y}"
12
+ "right: #{right}, "\
13
+ "top: #{top}, "\
14
+ "bottom #{bottom}, "\
15
+ "position x: #{position_x}, "\
16
+ "position y: #{position_y}"
17
17
  end
18
18
 
19
19
  # Parse TablePosition object
@@ -26,7 +26,7 @@ module OoxmlParser
26
26
  # @return [String] result of conversion
27
27
  def to_s
28
28
  "first line indent: #{@first_line_indent}, left indent: #{@left_indent}, "\
29
- "right indent: #{@right_indent}, hanging indent: #{@hanging_indent}"
29
+ "right indent: #{@right_indent}, hanging indent: #{@hanging_indent}"
30
30
  end
31
31
 
32
32
  # Parse Indents
@@ -84,7 +84,7 @@ module OoxmlParser
84
84
 
85
85
  # @return [True, false] if structure contain any user data
86
86
  def with_data?
87
- !nonempty_runs.empty? || paragraph_properties.section_properties
87
+ !nonempty_runs.empty? || paragraph_properties&.section_properties
88
88
  end
89
89
 
90
90
  # Compare this object to other
@@ -4,6 +4,6 @@ module OoxmlParser
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
6
  # [String] Version of Gem
7
- STRING = '0.13.0'
7
+ STRING = '0.15.0'
8
8
  end
9
9
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for parsing <definedName> tag
5
+ class DefinedName < OOXMLDocumentObject
6
+ # @return [String] Ranges to which defined name refers
7
+ attr_reader :range
8
+ # @return [String] Name
9
+ attr_reader :name
10
+ # @return [String] Id of sheet
11
+ attr_reader :local_sheet_id
12
+ # @return [Symbol] Specifies whether defined name is hidden
13
+ attr_reader :hidden
14
+
15
+ # Parse Defined Name data
16
+ # @param [Nokogiri::XML:Element] node with DefinedName data
17
+ # @return [DefinedName] value of DefinedName
18
+ def parse(node)
19
+ @range = node.text
20
+ node.attributes.each do |key, value|
21
+ case key
22
+ when 'name'
23
+ @name = value.value.to_s
24
+ when 'localSheetId'
25
+ @local_sheet_id = value.value.to_i
26
+ when 'hidden'
27
+ @hidden = attribute_enabled?(value)
28
+ end
29
+ end
30
+ self
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Parsing `dxfs` tag
5
+ class DifferentialFormattingRecords < OOXMLDocumentObject
6
+ # @return [Array, DifferentialFormattingRecord] list of formatting records
7
+ attr_reader :differential_formatting_records
8
+ # @return [Integer] count of formats
9
+ attr_reader :count
10
+
11
+ def initialize(parent: nil)
12
+ @differential_formatting_records = []
13
+ super
14
+ end
15
+
16
+ # @return [Array, DifferentialFormattingRecord] accessor
17
+ def [](key)
18
+ @differential_formatting_records[key]
19
+ end
20
+
21
+ # Parse DifferentialFormattingRecords data
22
+ # @param [Nokogiri::XML:Element] node with DifferentialFormattingRecords data
23
+ # @return [DifferentialFormattingRecords] value of DifferentialFormattingRecords data
24
+ def parse(node)
25
+ node.attributes.each do |key, value|
26
+ case key
27
+ when 'count'
28
+ @count = value.value.to_i
29
+ end
30
+ end
31
+
32
+ node.xpath('*').each do |node_child|
33
+ case node_child.name
34
+ when 'dxf'
35
+ @differential_formatting_records << DifferentialFormattingRecord.new(parent: self).parse(node_child)
36
+ end
37
+ end
38
+ self
39
+ end
40
+ end
41
+ end
@@ -5,6 +5,7 @@ require_relative 'style_sheet/fills'
5
5
  require_relative 'style_sheet/fonts'
6
6
  require_relative 'style_sheet/number_formats'
7
7
  require_relative 'style_sheet/xlsx_borders'
8
+ require_relative 'style_sheet/differential_formatting_records'
8
9
  module OoxmlParser
9
10
  # Parsing file styles.xml
10
11
  class StyleSheet < OOXMLDocumentObject
@@ -18,6 +19,8 @@ module OoxmlParser
18
19
  attr_reader :cell_xfs
19
20
  # @return [XlsxBorders] Cell XFs
20
21
  attr_reader :borders
22
+ # @return [DifferentialFormattingRecords] list of differential formatting records
23
+ attr_reader :differential_formatting_records
21
24
 
22
25
  def initialize(parent: nil)
23
26
  @number_formats = NumberFormats.new(parent: self)
@@ -42,6 +45,8 @@ module OoxmlParser
42
45
  @cell_xfs = CellXfs.new(parent: self).parse(node_child)
43
46
  when 'borders'
44
47
  @borders = XlsxBorders.new(parent: self).parse(node_child)
48
+ when 'dxfs'
49
+ @differential_formatting_records = DifferentialFormattingRecords.new(parent: self).parse(node_child)
45
50
  end
46
51
  end
47
52
  self
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for `colorScale` data
5
+ class ColorScale < OOXMLDocumentObject
6
+ # @return [Array<ConditionalFormatValueObject>] list of values
7
+ attr_reader :values
8
+ # @return [Array<OoxmlColor>] list of colors
9
+ attr_reader :colors
10
+
11
+ def initialize(parent: nil)
12
+ @values = []
13
+ @colors = []
14
+ super
15
+ end
16
+
17
+ # Parse ColorScale data
18
+ # @param [Nokogiri::XML:Element] node with ColorScale data
19
+ # @return [ColorScale] value of ColorScale data
20
+ def parse(node)
21
+ node.xpath('*').each do |node_child|
22
+ case node_child.name
23
+ when 'cfvo'
24
+ @values << ConditionalFormatValueObject.new(parent: self).parse(node_child)
25
+ when 'color'
26
+ @colors << OoxmlColor.new(parent: self).parse(node_child)
27
+ end
28
+ end
29
+ self
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for `cfvo` data
5
+ class ConditionalFormatValueObject < OOXMLDocumentObject
6
+ # @return [Symbol] Value type
7
+ attr_reader :type
8
+ # @return [String] Value
9
+ attr_reader :value
10
+ # @return [Symbol] Specifies whether value uses greater than or equal to operator
11
+ attr_reader :greater_or_equal
12
+ # @return [Formula] Formula
13
+ attr_reader :formula
14
+
15
+ def initialize(parent: nil)
16
+ @greater_or_equal = true
17
+ super
18
+ end
19
+
20
+ # Parse ConditionalFormatValueObject data
21
+ # @param [Nokogiri::XML:Element] node with ConditionalFormatValueObject data
22
+ # @return [ConditionalFormatValueObject] value of ConditionalFormatValueObject data
23
+ def parse(node)
24
+ node.attributes.each do |key, value|
25
+ case key
26
+ when 'type'
27
+ @type = value.value.to_sym
28
+ when 'val'
29
+ @value = value.value.to_s
30
+ when 'gte'
31
+ @greater_or_equal = attribute_enabled?(value)
32
+ end
33
+ end
34
+
35
+ node.xpath('*').each do |node_child|
36
+ case node_child.name
37
+ when 'f'
38
+ @formula = Formula.new(parent: self).parse(node_child)
39
+ end
40
+ end
41
+ self
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'data_bar/conditional_format_value_object'
4
+ module OoxmlParser
5
+ # Class for `dataBar` data
6
+ class DataBar < OOXMLDocumentObject
7
+ # @return [Integer] Minimal length of the data bar as a percentage of the cell width
8
+ attr_reader :min_length
9
+ # @return [Integer] Maximal length of the data bar as a percentage of the cell width
10
+ attr_reader :max_length
11
+ # @return [Symbol] Specifies whether value is shown in a cell
12
+ attr_reader :show_value
13
+ # @return [Symbol] Position of axis in a cell
14
+ attr_reader :axis_position
15
+ # @return [Symbol] Data bar direction
16
+ attr_reader :direction
17
+ # @return [Symbol] Specifies whether data bar fill is gradient
18
+ attr_reader :gradient
19
+ # @return [Symbol] Specifies whether data bar has border
20
+ attr_reader :border
21
+ # @return [Symbol] Specifies whether fill color for negative values is same as for positive
22
+ attr_reader :negative_bar_same_as_positive
23
+ # @return [Symbol] Specifies whether border color for negative values is same as for positive
24
+ attr_reader :negative_border_same_as_positive
25
+ # @return [Array, ConditionalFormatValueObject] minimal and maximal value
26
+ attr_reader :values
27
+ # @return [Color] Fill color for positive values
28
+ attr_reader :fill_color
29
+ # @return [Color] Fill color for negative values
30
+ attr_reader :negative_fill_color
31
+ # @return [Color] Border color for positive values
32
+ attr_reader :border_color
33
+ # @return [Color] Border color for negative values
34
+ attr_reader :negative_border_color
35
+ # @return [Color] Axis color
36
+ attr_reader :axis_color
37
+
38
+ def initialize(parent: nil)
39
+ @values = []
40
+ @show_value = true
41
+ @gradient = true
42
+ @negative_border_same_as_positive = true
43
+ super
44
+ end
45
+
46
+ # Parse DataBar data
47
+ # @param [Nokogiri::XML:Element] node with DataBar data
48
+ # @return [DataBar] value of DataBar data
49
+ def parse(node)
50
+ node.attributes.each do |key, value|
51
+ case key
52
+ when 'minLength'
53
+ @min_length = value.value.to_i
54
+ when 'maxLength'
55
+ @max_length = value.value.to_i
56
+ when 'showValue'
57
+ @show_value = attribute_enabled?(value)
58
+ when 'axisPosition'
59
+ @axis_position = value.value.to_sym
60
+ when 'direction'
61
+ @direction = value.value.to_sym
62
+ when 'gradient'
63
+ @gradient = attribute_enabled?(value)
64
+ when 'border'
65
+ @border = attribute_enabled?(value)
66
+ when 'negativeBarColorSameAsPositive'
67
+ @negative_bar_same_as_positive = attribute_enabled?(value)
68
+ when 'negativeBarBorderColorSameAsPositive'
69
+ @negative_border_same_as_positive = attribute_enabled?(value)
70
+ end
71
+ end
72
+
73
+ node.xpath('*').each do |node_child|
74
+ case node_child.name
75
+ when 'cfvo'
76
+ @values << ConditionalFormatValueObject.new(parent: self).parse(node_child)
77
+ when 'fillColor'
78
+ @fill_color = OoxmlColor.new(parent: self).parse(node_child)
79
+ when 'negativeFillColor'
80
+ @negative_fill_color = OoxmlColor.new(parent: self).parse(node_child)
81
+ when 'borderColor'
82
+ @border_color = OoxmlColor.new(parent: self).parse(node_child)
83
+ when 'negativeBorderColor'
84
+ @negative_border_color = OoxmlColor.new(parent: self).parse(node_child)
85
+ when 'axisColor'
86
+ @axis_color = OoxmlColor.new(parent: self).parse(node_child)
87
+ end
88
+ end
89
+ self
90
+ end
91
+
92
+ # @return [ConditionalFormatValueObject] minimal value
93
+ def minimum
94
+ values[0]
95
+ end
96
+
97
+ # @return [ConditionalFormatValueObject] maximal value
98
+ def maximum
99
+ values[1]
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for `dxf` data
5
+ class DifferentialFormattingRecord < OOXMLDocumentObject
6
+ # @return [Font] Font
7
+ attr_reader :font
8
+ # @return [NumberFormat] Number format
9
+ attr_reader :number_format
10
+ # @return [Fill] Fill
11
+ attr_reader :fill
12
+ # @return [Borders] Borders
13
+ attr_reader :borders
14
+
15
+ # Parse DifferentialFormattingRecord data
16
+ # @param [Nokogiri::XML:Element] node with DifferentialFormattingRecord data
17
+ # @return [DifferentialFormattingRecord] value of DifferentialFormattingRecord data
18
+ def parse(node)
19
+ node.xpath('*').each do |node_child|
20
+ case node_child.name
21
+ when 'font'
22
+ @font = Font.new(parent: self).parse(node_child)
23
+ when 'numFmt'
24
+ @number_format = NumberFormat.new(parent: self).parse(node_child)
25
+ when 'fill'
26
+ @fill = Fill.new(parent: self).parse(node_child)
27
+ when 'border'
28
+ @borders = XlsxBorder.new(parent: self).parse(node_child)
29
+ end
30
+ end
31
+ self
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for `cfIcon` data
5
+ class ConditionalFormattingIcon < OOXMLDocumentObject
6
+ # @return [String] Name of icon set
7
+ attr_reader :icon_set
8
+ # @return [Integer] Id of icon in set
9
+ attr_reader :icon_id
10
+
11
+ # Parse ConditionalFormattingIcon data
12
+ # @param [Nokogiri::XML:Element] node with ConditionalFormattingIcon data
13
+ # @return [ConditionalFormattingIcon] value of ConditionalFormattingIcon data
14
+ def parse(node)
15
+ node.attributes.each do |key, value|
16
+ case key
17
+ when 'iconSet'
18
+ @icon_set = value.value.to_s
19
+ when 'iconId'
20
+ @icon_id = value.value.to_i
21
+ end
22
+ end
23
+ self
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'icon_set/conditional_formatting_icon'
4
+ module OoxmlParser
5
+ # Class for `iconSet` data
6
+ class IconSet < OOXMLDocumentObject
7
+ # @return [String] Name of icon set
8
+ attr_reader :set
9
+ # @return [Symbol] Specifies whether icons are shown in reverse order
10
+ attr_reader :reverse
11
+ # @return [Symbol] Specifies whether value is shown in a cell
12
+ attr_reader :show_value
13
+ # @return [Symbol] Specifies whether icon set is custom
14
+ attr_reader :custom
15
+ # @return [Array<ConditionalFormatValueObject>] list of values
16
+ attr_reader :values
17
+ # @return [Array<ConditionalFormattingIcon>] list of icons for custom sets
18
+ attr_reader :icons
19
+
20
+ def initialize(parent: nil)
21
+ @values = []
22
+ @icons = []
23
+ @show_value = true
24
+ super
25
+ end
26
+
27
+ # Parse IconSet data
28
+ # @param [Nokogiri::XML:Element] node with IconSet data
29
+ # @return [IconSet] value of IconSet data
30
+ def parse(node)
31
+ node.attributes.each do |key, value|
32
+ case key
33
+ when 'iconSet'
34
+ @set = value.value.to_s
35
+ when 'reverse'
36
+ @reverse = attribute_enabled?(value)
37
+ when 'showValue'
38
+ @show_value = attribute_enabled?(value)
39
+ when 'custom'
40
+ @custom = attribute_enabled?(value)
41
+ end
42
+ end
43
+
44
+ node.xpath('*').each do |node_child|
45
+ case node_child.name
46
+ when 'cfvo'
47
+ @values << ConditionalFormatValueObject.new(parent: self).parse(node_child)
48
+ when 'cfIcon'
49
+ @icons << ConditionalFormattingIcon.new(parent: self).parse(node_child)
50
+ end
51
+ end
52
+ self
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'conditional_formatting_rule/differential_formatting_record'
4
+ require_relative 'conditional_formatting_rule/data_bar'
5
+ require_relative 'conditional_formatting_rule/color_scale'
6
+ require_relative 'conditional_formatting_rule/icon_set'
7
+ module OoxmlParser
8
+ # Class for `cfRule` data
9
+ class ConditionalFormattingRule < OOXMLDocumentObject
10
+ # @return [Symbol] Type of rule
11
+ attr_reader :type
12
+ # @return [Integer] Specifies position on the list of rules
13
+ attr_reader :priority
14
+ # @return [String] ID of rule
15
+ attr_reader :id
16
+ # @return [Integer] index of format
17
+ attr_reader :format_index
18
+ # @return [Symbol] Specifies whether rules with lower priority should be applied over this rule
19
+ attr_reader :stop_if_true
20
+ # @return [Symbol] Relational operator in value rule
21
+ attr_reader :operator
22
+ # @return [Symbol] Specifies whether percent is used in top/bottom rule
23
+ attr_reader :percent
24
+ # @return [Integer] Number of items in top/bottom rule
25
+ attr_reader :rank
26
+ # @return [Integer] Number of standard deviations in above/below average rule
27
+ attr_reader :standard_deviation
28
+ # @return [String] text value in text rule
29
+ attr_reader :text
30
+ # @return [Array, Formula] Formulas to determine condition
31
+ attr_reader :formulas
32
+ # @return [DifferentialFormattingRecord] Format
33
+ attr_reader :rule_format
34
+ # @return [DataBar] data bar formatting
35
+ attr_reader :data_bar
36
+ # @return [ColorScale] color scale formatting
37
+ attr_reader :color_scale
38
+ # @return [IconSet] icon set formatting
39
+ attr_reader :icon_set
40
+
41
+ def initialize(parent: nil)
42
+ @formulas = []
43
+ super
44
+ end
45
+
46
+ # Parse ConditionalFormattingRule data
47
+ # @param [Nokogiri::XML:Element] node with ConditionalFormattingRule data
48
+ # @return [ConditionalFormattingRule] value of ConditionalFormattingRule data
49
+ def parse(node)
50
+ node.attributes.each do |key, value|
51
+ case key
52
+ when 'type'
53
+ @type = value.value.to_sym
54
+ when 'priority'
55
+ @priority = value.value.to_i
56
+ when 'id'
57
+ @id = value.value.to_s
58
+ when 'dxfId'
59
+ @format_index = value.value.to_i
60
+ when 'stopIfTrue'
61
+ @stop_if_true = attribute_enabled?(value)
62
+ when 'operator'
63
+ @operator = value.value.to_sym
64
+ when 'percent'
65
+ @percent = attribute_enabled?(value)
66
+ when 'rank'
67
+ @rank = value.value.to_i
68
+ when 'stdDev'
69
+ @standard_deviation = value.value.to_i
70
+ when 'text'
71
+ @text = value.text.to_s
72
+ end
73
+ end
74
+
75
+ node.xpath('*').each do |node_child|
76
+ case node_child.name
77
+ when 'f'
78
+ @formulas << Formula.new(parent: self).parse(node_child)
79
+ when 'dxf'
80
+ @rule_format = DifferentialFormattingRecord.new(parent: self).parse(node_child)
81
+ when 'dataBar'
82
+ @data_bar = DataBar.new(parent: self).parse(node_child)
83
+ when 'colorScale'
84
+ @color_scale = ColorScale.new(parent: self).parse(node_child)
85
+ when 'iconSet'
86
+ @icon_set = IconSet.new(parent: self).parse(node_child)
87
+ end
88
+ end
89
+ self
90
+ end
91
+
92
+ # @return [nil, DifferentialFormattingRecord] format of rule
93
+ def format
94
+ return @rule_format if @rule_format
95
+ return nil unless @format_index
96
+
97
+ root_object.style_sheet.differential_formatting_records[@format_index]
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'conditional_formatting/conditional_formatting_rule'
4
+ module OoxmlParser
5
+ # Class for `conditionalFormatting` data
6
+ class ConditionalFormatting < OOXMLDocumentObject
7
+ # @return [Array, ConditionalFormattingRule] list of conditional formatting rules
8
+ attr_reader :rules
9
+ # @return [String] Ranges to which conditional formatting is applied
10
+ attr_reader :reference_sequence
11
+
12
+ def initialize(parent: nil)
13
+ @rules = []
14
+ super
15
+ end
16
+
17
+ # Parse ConditionalFormatting data
18
+ # @param [Nokogiri::XML:Element] node with ConditionalFormatting data
19
+ # @return [ConditionalFormatting] value of ConditionalFormatting data
20
+ def parse(node)
21
+ node.xpath('*').each do |node_child|
22
+ case node_child.name
23
+ when 'cfRule'
24
+ @rules << ConditionalFormattingRule.new(parent: self).parse(node_child)
25
+ when 'sqref'
26
+ @reference_sequence = node_child.text
27
+ end
28
+ end
29
+ self
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'conditional_formattings/conditional_formatting'
4
+ module OoxmlParser
5
+ # Class for `conditionalFormattings` data
6
+ class ConditionalFormattings < OOXMLDocumentObject
7
+ # @return [Array<ConditionalFormatting>] list of conditional formattings
8
+ attr_reader :conditional_formattings_list
9
+
10
+ def initialize(parent: nil)
11
+ @conditional_formattings_list = []
12
+ super
13
+ end
14
+
15
+ # @return [Array, ConditionalFormatting] accessor
16
+ def [](key)
17
+ @conditional_formattings_list[key]
18
+ end
19
+
20
+ # Parse ConditionalFormattings data
21
+ # @param [Nokogiri::XML:Element] node with ConditionalFormattings data
22
+ # @return [ConditionalFormattings] value of ConditionalFormattings data
23
+ def parse(node)
24
+ node.xpath('*').each do |node_child|
25
+ case node_child.name
26
+ when 'conditionalFormatting'
27
+ @conditional_formattings_list << ConditionalFormatting.new(parent: self).parse(node_child)
28
+ end
29
+ end
30
+ self
31
+ end
32
+ end
33
+ end
@@ -3,11 +3,14 @@
3
3
  require_relative 'extension/data_validations'
4
4
  require_relative 'extension/sparkline_groups'
5
5
  require_relative 'extension/x14_table'
6
+ require_relative 'extension/conditional_formattings'
6
7
  module OoxmlParser
7
8
  # Class for `ext` data
8
9
  class Extension < OOXMLDocumentObject
9
10
  # @return [DataValidations] list of data validations
10
11
  attr_accessor :data_validations
12
+ # @return [ConditionalFormattings] list of conditional formattings
13
+ attr_reader :conditional_formattings
11
14
  # @return [X14Table] table data in x14 namespace
12
15
  attr_accessor :table
13
16
  # @return [SparklineGroups] list of groups
@@ -21,6 +24,8 @@ module OoxmlParser
21
24
  case column_node.name
22
25
  when 'dataValidations'
23
26
  @data_validations = DataValidations.new(parent: self).parse(column_node)
27
+ when 'conditionalFormattings'
28
+ @conditional_formattings = ConditionalFormattings.new(parent: self).parse(column_node)
24
29
  when 'table'
25
30
  @table = X14Table.new(parent: self).parse(column_node)
26
31
  when 'sparklineGroups'
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for parsing header or footer
5
+ class HeaderFooterChild < OOXMLDocumentObject
6
+ # @return [Symbol] type of header
7
+ attr_reader :type
8
+ # @return [String] raw text of header
9
+ attr_reader :raw_string
10
+
11
+ def initialize(type: nil, raw_string: nil, parent: nil)
12
+ @type = type
13
+ @raw_string = raw_string
14
+ super(parent: parent)
15
+ end
16
+
17
+ # Parse HeaderFooterChild data
18
+ # @param node [Nokogiri::XML:Element] node to parse
19
+ # @return [HeaderFooterChild] result of parsing
20
+ def parse(node)
21
+ @raw_string = node.text
22
+ self
23
+ end
24
+
25
+ # @return [String] right part of header
26
+ def right
27
+ return @right if @right
28
+
29
+ right = @raw_string.match(/&R(.+)/)
30
+ return nil unless right
31
+
32
+ @right = right[1]
33
+ end
34
+
35
+ # @return [String] center part of header
36
+ def center
37
+ return @center if @center
38
+
39
+ center = @raw_string.split('&R').first.match(/&C(.+)/)
40
+ return nil unless center
41
+
42
+ @center = center[1]
43
+ end
44
+
45
+ # @return [String] left part of header
46
+ def left
47
+ return @left if @left
48
+
49
+ left = @raw_string.gsub("&R#{right}", '')
50
+ left = left.gsub("&C#{center}", '')
51
+ return nil if left == ''
52
+
53
+ left.gsub('&L', '')
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'xlsx_header_footer/header_footer_child'
4
+ module OoxmlParser
5
+ # Class for parsing <headerFooter> tag
6
+ class XlsxHeaderFooter < OOXMLDocumentObject
7
+ # @return [Symbol] Specifies whether to align header with margins
8
+ attr_reader :align_with_margins
9
+ # @return [Symbol] Specifies whether first header is different
10
+ attr_reader :different_first
11
+ # @return [Symbol] Specifies whether odd and even headers are different
12
+ attr_reader :different_odd_even
13
+ # @return [Symbol] Specifies whether to scale header with document
14
+ attr_reader :scale_with_document
15
+ # @return [String] odd header
16
+ attr_reader :odd_header
17
+ # @return [String] odd footer
18
+ attr_reader :odd_footer
19
+ # @return [String] even header
20
+ attr_reader :even_header
21
+ # @return [String] even footer
22
+ attr_reader :even_footer
23
+ # @return [String] first header
24
+ attr_reader :first_header
25
+ # @return [String] first footer
26
+ attr_reader :first_footer
27
+
28
+ # Parse Header Footer data
29
+ # @param node [Nokogiri::XML:Element] node to parse
30
+ # @return [XlsxHeaderFooter] result of parsing
31
+ def parse(node)
32
+ node.attributes.each do |key, value|
33
+ case key
34
+ when 'alignWithMargins'
35
+ @align_with_margins = attribute_enabled?(value)
36
+ when 'differentFirst'
37
+ @different_first = attribute_enabled?(value)
38
+ when 'differentOddEven'
39
+ @different_odd_even = attribute_enabled?(value)
40
+ when 'scaleWithDoc'
41
+ @scale_with_document = attribute_enabled?(value)
42
+ end
43
+
44
+ node.xpath('*').each do |node_child|
45
+ case node_child.name
46
+ when 'oddHeader'
47
+ @odd_header = HeaderFooterChild.new(parent: parent, type: odd_header).parse(node_child)
48
+ when 'oddFooter'
49
+ @odd_footer = HeaderFooterChild.new(parent: parent, type: odd_footer).parse(node_child)
50
+ when 'evenHeader'
51
+ @even_header = HeaderFooterChild.new(parent: parent, type: even_header).parse(node_child)
52
+ when 'evenFooter'
53
+ @even_footer = HeaderFooterChild.new(parent: parent, type: even_footer).parse(node_child)
54
+ when 'firstHeader'
55
+ @first_header = HeaderFooterChild.new(parent: parent, type: first_header).parse(node_child)
56
+ when 'firstFooter'
57
+ @first_footer = HeaderFooterChild.new(parent: parent, type: first_footer).parse(node_child)
58
+ end
59
+ end
60
+ end
61
+ self
62
+ end
63
+ end
64
+ end
@@ -10,6 +10,7 @@ require_relative 'worksheet/worksheet_helper'
10
10
  require_relative 'worksheet/xlsx_column_properties'
11
11
  require_relative 'worksheet/xlsx_drawing'
12
12
  require_relative 'worksheet/xlsx_row'
13
+ require_relative 'worksheet/xlsx_header_footer'
13
14
  module OoxmlParser
14
15
  # Properties of worksheet
15
16
  class Worksheet < OOXMLDocumentObject
@@ -28,6 +29,10 @@ module OoxmlParser
28
29
  attr_reader :page_setup
29
30
  # @return [ExtensionList] list of extensions
30
31
  attr_accessor :extension_list
32
+ # @return [XlsxHeaderFooter] header and footer
33
+ attr_reader :header_footer
34
+ # @return [Array<ConditionalFormatting>] list of conditional formattings
35
+ attr_reader :conditional_formattings
31
36
 
32
37
  def initialize(parent: nil)
33
38
  @columns = []
@@ -39,6 +44,7 @@ module OoxmlParser
39
44
  @drawings = []
40
45
  @sheet_views = []
41
46
  @table_parts = []
47
+ @conditional_formattings = []
42
48
  super
43
49
  end
44
50
 
@@ -124,6 +130,10 @@ module OoxmlParser
124
130
  @page_setup = PageSetup.new(parent: self).parse(worksheet_node_child)
125
131
  when 'extLst'
126
132
  @extension_list = ExtensionList.new(parent: self).parse(worksheet_node_child)
133
+ when 'headerFooter'
134
+ @header_footer = XlsxHeaderFooter.new(parent: self).parse(worksheet_node_child)
135
+ when 'conditionalFormatting'
136
+ @conditional_formattings << ConditionalFormatting.new(parent: self).parse(worksheet_node_child)
127
137
  end
128
138
  end
129
139
  parse_comments
@@ -3,6 +3,7 @@
3
3
  require_relative 'workbook/chartsheet'
4
4
  require_relative 'workbook/pivot_cache'
5
5
  require_relative 'workbook/pivot_table_definition'
6
+ require_relative 'workbook/defined_name'
6
7
  require_relative 'workbook/shared_string_table'
7
8
  require_relative 'workbook/style_sheet'
8
9
  require_relative 'workbook/worksheet'
@@ -24,11 +25,14 @@ module OoxmlParser
24
25
  attr_accessor :pivot_caches
25
26
  # @return [Array<PivotTableDefintion>] list of pivot table defitions
26
27
  attr_accessor :pivot_table_definitions
28
+ # @return [Array<DefinedName>] list of defined names
29
+ attr_reader :defined_names
27
30
 
28
31
  def initialize(params = {})
29
32
  @worksheets = []
30
33
  @pivot_caches = []
31
34
  @pivot_table_definitions = []
35
+ @defined_names = []
32
36
  super
33
37
  end
34
38
 
@@ -125,6 +129,7 @@ module OoxmlParser
125
129
  end
126
130
  parse_pivot_cache
127
131
  parse_pivot_table
132
+ parse_defined_names
128
133
  OOXMLDocumentObject.xmls_stack.pop
129
134
  self
130
135
  end
@@ -149,5 +154,12 @@ module OoxmlParser
149
154
  @pivot_table_definitions << PivotTableDefinition.new(parent: self).parse(file.part_name)
150
155
  end
151
156
  end
157
+
158
+ # Perform parsing of defined names
159
+ def parse_defined_names
160
+ @doc.xpath('xmlns:workbook/xmlns:definedNames/xmlns:definedName').each do |defined_name|
161
+ @defined_names << DefinedName.new(parent: self).parse(defined_name)
162
+ end
163
+ end
152
164
  end
153
165
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooxml_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-05-25 00:00:00.000000000 Z
13
+ date: 2021-09-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -486,6 +486,7 @@ files:
486
486
  - lib/ooxml_parser/version.rb
487
487
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb
488
488
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/chartsheet.rb
489
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/defined_name.rb
489
490
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache.rb
490
491
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition.rb
491
492
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_fields.rb
@@ -508,6 +509,7 @@ files:
508
509
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs.rb
509
510
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/cell_style/alignment.rb
510
511
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/xf.rb
512
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/differential_formatting_records.rb
511
513
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills.rb
512
514
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb
513
515
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill/pattern_fill.rb
@@ -535,6 +537,15 @@ files:
535
537
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter/filter_column/custom_filters/custom_filter.rb
536
538
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list.rb
537
539
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension.rb
540
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings.rb
541
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting.rb
542
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule.rb
543
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/color_scale.rb
544
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/data_bar.rb
545
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/data_bar/conditional_format_value_object.rb
546
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/differential_formatting_record.rb
547
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/icon_set.rb
548
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/conditional_formattings/conditional_formatting/conditional_formatting_rule/icon_set/conditional_formatting_icon.rb
538
549
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/data_validations.rb
539
550
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/data_validations/data_validation.rb
540
551
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/extension_list/extension/data_validations/data_validation/data_validation_formula.rb
@@ -548,6 +559,8 @@ files:
548
559
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
549
560
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb
550
561
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position_parameters.rb
562
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer.rb
563
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
551
564
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb
552
565
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb
553
566
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/formula.rb
@@ -576,7 +589,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
576
589
  - !ruby/object:Gem::Version
577
590
  version: '0'
578
591
  requirements: []
579
- rubygems_version: 3.1.6
592
+ rubygems_version: 3.2.27
580
593
  signing_key:
581
594
  specification_version: 4
582
595
  summary: OoxmlParser Gem