ooxml_parser 0.26.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d10481491c8a8bb901c8514f5a7c19ee3b6482e8fb943f39b9191dbd057d395
4
- data.tar.gz: efbdbe106e2e88c584e428b8536cedb96972033434b5e1457f6ae2b31946cdd4
3
+ metadata.gz: 7a5fdd9341474bc26ce030d37d3fbdfd75cf940c045d463e512c8e5fbb13f17a
4
+ data.tar.gz: 91205544439de08e01535cee8846b365c8d605d5cea03421ff143a4cb888723a
5
5
  SHA512:
6
- metadata.gz: b553b7f055d43a6a355592ac8c2d28b085795b0faadf12531f119d4a1d15b1c7bcd45a5a661aad611799aa3286266469b88c12792bb4c3bba0b6c3fac2a0f54d
7
- data.tar.gz: 1a68d32efafe9ee2921ffd6c75a794dd340a4b6d814e4aa7daa6348fb1246644a12b99a071df7e7e1bfe84de02f15c96a4068f6227008ec051a1932b0bdb01db
6
+ metadata.gz: 8663d4335fb1da6bc91718d741fe22eadecadfe5ed68bd7b6dbac11a9405c8a28c5e15bb602807e571eb0741dfe1fd532a7885229c26c9e0805ab444207096b4
7
+ data.tar.gz: b5047266930ed789e8595b419b6e01c074c9fbcca21868ed676724f986e84faf981b13bf8fb4451134ff80ee25f6e35762f93664ed1800d631819565901cc680
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for parsing Chart Style entry
5
+ class ChartStyleEntry < OOXMLDocumentObject
6
+ # @return [OOXMLShapeBodyProperties] body properties
7
+ attr_reader :body_properties
8
+ # @return [RunProperties] default run properties
9
+ attr_reader :default_run_properties
10
+ # @return [FillReference] effect reference
11
+ attr_reader :effect_reference
12
+ # @return [FillReference] fill reference
13
+ attr_reader :fill_reference
14
+ # @return [FontReference] font reference
15
+ attr_reader :font_reference
16
+ # @return [StyleMatrixReference] line style reference
17
+ attr_reader :line_style_reference
18
+ # @return [StyleMatrixReference] shape properties
19
+ attr_reader :shape_properties
20
+
21
+ # Parse Chart style entry
22
+ # @param node [Nokogiri::XML:Element] node to parse
23
+ # @return [ChartStyleEntry] result of parsing
24
+ def parse(node)
25
+ node.xpath('*').each do |node_child|
26
+ case node_child.name
27
+ when 'bodyPr'
28
+ @body_properties = OOXMLShapeBodyProperties.new(parent: self).parse(node_child)
29
+ when 'defRPr'
30
+ @default_run_properties = RunProperties.new(parent: self).parse(node_child)
31
+ when 'effectRef'
32
+ @effect_reference = StyleMatrixReference.new(parent: self).parse(node_child)
33
+ when 'fillRef'
34
+ @fill_reference = StyleMatrixReference.new(parent: self).parse(node_child)
35
+ when 'fontRef'
36
+ @font_reference = FontReference.new(parent: self).parse(node_child)
37
+ when 'lnRef'
38
+ @line_style_reference = StyleMatrixReference.new(parent: self).parse(node_child)
39
+ when 'spPr'
40
+ @shape_properties = DocxShapeProperties.new(parent: self).parse(node_child)
41
+ end
42
+ end
43
+ self
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for parsing marker layout
5
+ class MarkerLayout < OOXMLDocumentObject
6
+ # @return [Integer] size of marker
7
+ attr_reader :size
8
+ # @return [Symbol] symbol of marker
9
+ attr_reader :symbol
10
+
11
+ # Parse Marker Layout
12
+ # @param node [Nokogiri::XML:Element] node to parse
13
+ # @return [MarkerLayout] result of parsing
14
+ def parse(node)
15
+ node.attributes.each do |key, value|
16
+ case key
17
+ when 'size'
18
+ @size = value.value.to_i
19
+ when 'symbol'
20
+ @symbol = value.value.to_sym
21
+ end
22
+ end
23
+ self
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'chart_style_file/chart_style_entry'
4
+ require_relative 'chart_style_file/marker_layout'
5
+ module OoxmlParser
6
+ # Class for parsing Chart Style data from file
7
+ class ChartStyleFile < OOXMLDocumentObject
8
+ # @return [ChartStyleEntry] axis title entry
9
+ attr_reader :axis_title
10
+ # @return [ChartStyleEntry] axis category entry
11
+ attr_reader :category_axis
12
+ # @return [ChartStyleEntry] chart area entry
13
+ attr_reader :chart_area
14
+ # @return [ChartStyleEntry] data label entry
15
+ attr_reader :data_label
16
+ # @return [ChartStyleEntry] data label entry
17
+ attr_reader :data_label_callout
18
+ # @return [ChartStyleEntry] data point entry
19
+ attr_reader :data_point
20
+ # @return [ChartStyleEntry] data point 3d entry
21
+ attr_reader :data_point_3d
22
+ # @return [ChartStyleEntry] data point line entry
23
+ attr_reader :data_point_line
24
+ # @return [ChartStyleEntry] data point marker entry
25
+ attr_reader :data_point_marker
26
+ # @return [ChartStyleEntry] data point marker layout entry
27
+ attr_reader :data_point_marker_layout
28
+ # @return [ChartStyleEntry] data point wireframe entry
29
+ attr_reader :data_point_wireframe
30
+ # @return [ChartStyleEntry] data table entry
31
+ attr_reader :data_table
32
+ # @return [ChartStyleEntry] down bar entry
33
+ attr_reader :down_bar
34
+ # @return [ChartStyleEntry] drop line entry
35
+ attr_reader :drop_line
36
+ # @return [ChartStyleEntry] error bar entry
37
+ attr_reader :error_bar
38
+ # @return [ChartStyleEntry] floor entry
39
+ attr_reader :floor
40
+ # @return [ChartStyleEntry] gridline major entry
41
+ attr_reader :gridline_major
42
+ # @return [ChartStyleEntry] gridline minor entry
43
+ attr_reader :gridline_minor
44
+ # @return [ChartStyleEntry] high low line entry
45
+ attr_reader :high_low_line
46
+ # @return [ChartStyleEntry] leader line entry
47
+ attr_reader :leader_line
48
+ # @return [ChartStyleEntry] legend entry
49
+ attr_reader :legend
50
+ # @return [ChartStyleEntry] plot area entry
51
+ attr_reader :plot_area
52
+ # @return [ChartStyleEntry] plot area 3d entry
53
+ attr_reader :plot_area_3d
54
+ # @return [ChartStyleEntry] series axis entry
55
+ attr_reader :series_axis
56
+ # @return [ChartStyleEntry] series line entry
57
+ attr_reader :series_line
58
+ # @return [ChartStyleEntry] title entry
59
+ attr_reader :title
60
+ # @return [ChartStyleEntry] trend line entry
61
+ attr_reader :trend_line
62
+ # @return [ChartStyleEntry] trend line label entry
63
+ attr_reader :trend_line_label
64
+ # @return [ChartStyleEntry] up bar entry
65
+ attr_reader :up_bar
66
+ # @return [ChartStyleEntry] value axis entry
67
+ attr_reader :value_axis
68
+ # @return [ChartStyleEntry] wall entry
69
+ attr_reader :wall
70
+
71
+ # Parse Chart style file
72
+ # @return [ChartStyleFile] result of parsing
73
+ def parse(file)
74
+ xml = parse_xml(file)
75
+ xml.xpath('cs:chartStyle/*').each do |chart_node|
76
+ case chart_node.name
77
+ when 'axisTitle'
78
+ @axis_title = ChartStyleEntry.new(parent: self).parse(chart_node)
79
+ when 'categoryAxis'
80
+ @category_axis = ChartStyleEntry.new(parent: self).parse(chart_node)
81
+ when 'chartArea'
82
+ @chart_area = ChartStyleEntry.new(parent: self).parse(chart_node)
83
+ when 'dataLabel'
84
+ @data_label = ChartStyleEntry.new(parent: self).parse(chart_node)
85
+ when 'dataLabelCallout'
86
+ @data_label_callout = ChartStyleEntry.new(parent: self).parse(chart_node)
87
+ when 'dataPoint'
88
+ @data_point = ChartStyleEntry.new(parent: self).parse(chart_node)
89
+ when 'dataPoint3D'
90
+ @data_point_3d = ChartStyleEntry.new(parent: self).parse(chart_node)
91
+ when 'dataPointLine'
92
+ @data_point_line = ChartStyleEntry.new(parent: self).parse(chart_node)
93
+ when 'dataPointMarker'
94
+ @data_point_marker = ChartStyleEntry.new(parent: self).parse(chart_node)
95
+ when 'dataPointMarkerLayout'
96
+ @data_point_marker_layout = MarkerLayout.new(parent: self).parse(chart_node)
97
+ when 'dataPointWireframe'
98
+ @data_point_wireframe = ChartStyleEntry.new(parent: self).parse(chart_node)
99
+ when 'dataTable'
100
+ @data_table = ChartStyleEntry.new(parent: self).parse(chart_node)
101
+ when 'downBar'
102
+ @down_bar = ChartStyleEntry.new(parent: self).parse(chart_node)
103
+ when 'dropLine'
104
+ @drop_line = ChartStyleEntry.new(parent: self).parse(chart_node)
105
+ when 'errorBar'
106
+ @error_bar = ChartStyleEntry.new(parent: self).parse(chart_node)
107
+ when 'floor'
108
+ @floor = ChartStyleEntry.new(parent: self).parse(chart_node)
109
+ when 'gridlineMajor'
110
+ @gridline_major = ChartStyleEntry.new(parent: self).parse(chart_node)
111
+ when 'gridlineMinor'
112
+ @gridline_minor = ChartStyleEntry.new(parent: self).parse(chart_node)
113
+ when 'hiLoLine'
114
+ @high_low_line = ChartStyleEntry.new(parent: self).parse(chart_node)
115
+ when 'leaderLine'
116
+ @leader_line = ChartStyleEntry.new(parent: self).parse(chart_node)
117
+ when 'legend'
118
+ @legend = ChartStyleEntry.new(parent: self).parse(chart_node)
119
+ when 'plotArea'
120
+ @plot_area = ChartStyleEntry.new(parent: self).parse(chart_node)
121
+ when 'plotArea3D'
122
+ @plot_area_3d = ChartStyleEntry.new(parent: self).parse(chart_node)
123
+ when 'seriesAxis'
124
+ @series_axis = ChartStyleEntry.new(parent: self).parse(chart_node)
125
+ when 'seriesLine'
126
+ @series_line = ChartStyleEntry.new(parent: self).parse(chart_node)
127
+ when 'title'
128
+ @title = ChartStyleEntry.new(parent: self).parse(chart_node)
129
+ when 'trendline'
130
+ @trend_line = ChartStyleEntry.new(parent: self).parse(chart_node)
131
+ when 'trendlineLabel'
132
+ @trend_line_label = ChartStyleEntry.new(parent: self).parse(chart_node)
133
+ when 'upBar'
134
+ @up_bar = ChartStyleEntry.new(parent: self).parse(chart_node)
135
+ when 'valueAxis'
136
+ @value_axis = ChartStyleEntry.new(parent: self).parse(chart_node)
137
+ when 'wall'
138
+ @wall = ChartStyleEntry.new(parent: self).parse(chart_node)
139
+ end
140
+ end
141
+ self
142
+ end
143
+ end
144
+ end
@@ -5,6 +5,7 @@ require_relative 'chart_cells_range'
5
5
  require_relative 'chart_legend'
6
6
  require_relative 'chart_point'
7
7
  require_relative 'display_labels_properties'
8
+ require_relative 'chart/chart_style_file'
8
9
  require_relative 'chart/pivot_formats'
9
10
  require_relative 'chart/plot_area'
10
11
  require_relative 'chart/series'
@@ -28,6 +29,10 @@ module OoxmlParser
28
29
  attr_reader :vary_colors
29
30
  # @return [View3D] properties of 3D view
30
31
  attr_accessor :view_3d
32
+ # @return [ChartStyle] style of current chart
33
+ attr_reader :style
34
+ # @return [Relationships] relationships of chart
35
+ attr_reader :relationships
31
36
 
32
37
  def initialize(parent: nil)
33
38
  @axis_ids = []
@@ -154,6 +159,8 @@ module OoxmlParser
154
159
  end
155
160
  end
156
161
  end
162
+ parse_relationships
163
+ parse_style
157
164
  self
158
165
  end
159
166
 
@@ -170,5 +177,31 @@ module OoxmlParser
170
177
  end
171
178
  end
172
179
  end
180
+
181
+ # Parse relationship of chart
182
+ def parse_relationships
183
+ file_name = File.basename(OOXMLDocumentObject.current_xml)
184
+ relationship_file = "#{OOXMLDocumentObject.path_to_folder}" \
185
+ '/word/charts/' \
186
+ "_rels/#{file_name}.rels"
187
+
188
+ return unless File.exist?(relationship_file)
189
+
190
+ @relationships = Relationships.new(parent: self)
191
+ .parse_file(relationship_file)
192
+ end
193
+
194
+ def parse_style
195
+ return unless @relationships
196
+
197
+ chart_relationship = @relationships.target_by_type('chartStyle')
198
+ return if chart_relationship.empty?
199
+
200
+ chart_style_file = chart_relationship.first
201
+ style_file = "#{OOXMLDocumentObject.path_to_folder}" \
202
+ "/word/charts/#{chart_style_file}"
203
+
204
+ @style = ChartStyleFile.new(parent: self).parse(style_file)
205
+ end
173
206
  end
174
207
  end
@@ -156,7 +156,10 @@ module OoxmlParser
156
156
  # @param scheme_color_node [Nokogiri::XML:Element] node to parse
157
157
  # @return [Color] result of parsing
158
158
  def parse_scheme_color(scheme_color_node)
159
- color = root_object.theme.color_scheme[scheme_color_node.attribute('val').value.to_sym].color
159
+ color_scheme_color = root_object.theme.color_scheme[scheme_color_node.attribute('val').value.to_sym]
160
+ return unless color_scheme_color
161
+
162
+ color = color_scheme_color.color
160
163
  hls = color.to_hsl
161
164
  scheme_name = nil
162
165
  scheme_color_node.xpath('*').each do |scheme_color_node_child|
@@ -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.26.0'
7
+ STRING = '0.27.0'
8
8
  end
9
9
  end
@@ -4,7 +4,7 @@ require_relative 'xlsx_row/xlsx_cell'
4
4
  module OoxmlParser
5
5
  # Single Row of XLSX
6
6
  class XlsxRow < OOXMLDocumentObject
7
- attr_accessor :height, :style, :hidden
7
+ attr_accessor :height, :hidden
8
8
  # @return [True, False] true if the row height has been manually set.
9
9
  attr_accessor :custom_height
10
10
  # @return [Integer] Indicates to which row in the sheet
@@ -12,6 +12,8 @@ module OoxmlParser
12
12
  attr_accessor :index
13
13
  # @return [Array<Cells>] cells of row, as in xml structure
14
14
  attr_reader :cells_raw
15
+ # @return [Integer] index of style of row
16
+ attr_reader :style_index
15
17
 
16
18
  def initialize(parent: nil)
17
19
  @cells_raw = []
@@ -33,6 +35,8 @@ module OoxmlParser
33
35
  @hidden = option_enabled?(node, 'hidden')
34
36
  when 'r'
35
37
  @index = value.value.to_i
38
+ when 's'
39
+ @style_index = value.value.to_i
36
40
  end
37
41
  end
38
42
  node.xpath('*').each do |node_child|
@@ -55,5 +59,12 @@ module OoxmlParser
55
59
 
56
60
  @cells
57
61
  end
62
+
63
+ # @return [Xf, nil] style of row or `nil` if not applied
64
+ def style
65
+ return nil unless @style_index
66
+
67
+ root_object.style_sheet.cell_xfs.xf_array[@style_index]
68
+ end
58
69
  end
59
70
  end
@@ -17,7 +17,7 @@ module OoxmlParser
17
17
  # Properties of worksheet
18
18
  class Worksheet < OOXMLDocumentObject
19
19
  include WorksheetHelper
20
- attr_accessor :name, :rows, :merge, :charts, :hyperlinks, :drawings, :comments, :columns, :sheet_format_properties,
20
+ attr_accessor :name, :merge, :charts, :hyperlinks, :drawings, :comments, :columns, :sheet_format_properties,
21
21
  :autofilter, :table_parts, :sheet_views
22
22
  # @return [String] xml name of sheet
23
23
  attr_accessor :xml_name
@@ -39,11 +39,14 @@ module OoxmlParser
39
39
  attr_reader :sheet_protection
40
40
  # @return [Array<ProtectedRange>] list of protected ranges
41
41
  attr_reader :protected_ranges
42
+ # @return [Array<Row>] rows in sheet, as in xml structure
43
+ attr_reader :rows_raw
42
44
 
43
45
  def initialize(parent: nil)
44
46
  @columns = []
45
47
  @name = ''
46
48
  @rows = []
49
+ @rows_raw = []
47
50
  @merge = []
48
51
  @charts = []
49
52
  @hyperlinks = []
@@ -65,7 +68,7 @@ module OoxmlParser
65
68
 
66
69
  # @return [True, false] if structure contain any user data
67
70
  def with_data?
68
- return true unless @rows.empty?
71
+ return true unless @rows_raw.empty?
69
72
  return true unless default_columns?
70
73
  return true unless @drawings.empty?
71
74
  return true unless @charts.empty?
@@ -95,13 +98,10 @@ module OoxmlParser
95
98
  case worksheet_node_child.name
96
99
  when 'sheetData'
97
100
  worksheet_node_child.xpath('xmlns:row').each do |row_node|
98
- @rows[row_node.attribute('r').value.to_i - 1] = XlsxRow.new(parent: self).parse(row_node)
99
- @rows[row_node.attribute('r').value.to_i - 1].style = root_object.style_sheet.cell_xfs.xf_array[row_node.attribute('s').value.to_i] if row_node.attribute('s')
101
+ @rows_raw << XlsxRow.new(parent: self).parse(row_node)
100
102
  end
101
103
  when 'sheetFormatPr'
102
- if !worksheet_node_child.attribute('defaultColWidth').nil? && !worksheet_node_child.attribute('defaultRowHeight').nil?
103
- @sheet_format_properties = SheetFormatProperties.new(parent: self).parse(worksheet_node_child)
104
- end
104
+ @sheet_format_properties = SheetFormatProperties.new(parent: self).parse(worksheet_node_child)
105
105
  when 'mergeCells'
106
106
  worksheet_node_child.xpath('xmlns:mergeCell').each do |merge_node|
107
107
  @merge << merge_node.attribute('ref').value.to_s
@@ -154,6 +154,18 @@ module OoxmlParser
154
154
  self
155
155
  end
156
156
 
157
+ # @return [Array<XlsxRow, nil>] list of rows, with nil,
158
+ # if row data is not stored in xml
159
+ def rows
160
+ return @rows if @rows.any?
161
+
162
+ rows_raw.each do |row|
163
+ @rows[row.index - 1] = row
164
+ end
165
+
166
+ @rows
167
+ end
168
+
157
169
  private
158
170
 
159
171
  # Do work for parsing shared comments file
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.26.0
4
+ version: 0.27.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: 2022-08-22 00:00:00.000000000 Z
13
+ date: 2022-08-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -210,6 +210,9 @@ files:
210
210
  - lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice/math_text.rb
211
211
  - lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice/math_text/math_paragraph.rb
212
212
  - lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb
213
+ - lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/chart_style_file.rb
214
+ - lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/chart_style_file/chart_style_entry.rb
215
+ - lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/chart_style_file/marker_layout.rb
213
216
  - lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/pivot_formats.rb
214
217
  - lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/pivot_formats/pivot_format.rb
215
218
  - lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/plot_area.rb
@@ -605,7 +608,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
605
608
  - !ruby/object:Gem::Version
606
609
  version: '0'
607
610
  requirements: []
608
- rubygems_version: 3.3.20
611
+ rubygems_version: 3.3.21
609
612
  signing_key:
610
613
  specification_version: 4
611
614
  summary: OoxmlParser Gem