ooxml_parser 0.26.0 → 0.29.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d10481491c8a8bb901c8514f5a7c19ee3b6482e8fb943f39b9191dbd057d395
4
- data.tar.gz: efbdbe106e2e88c584e428b8536cedb96972033434b5e1457f6ae2b31946cdd4
3
+ metadata.gz: ae537423c384b461a5c2eb77bfe60b692ab334e1bd6ae22cc928e28230302997
4
+ data.tar.gz: c8696409b7862346b631367d7fa014ceea48e18deb3a6b9832fbb4dcc57dab13
5
5
  SHA512:
6
- metadata.gz: b553b7f055d43a6a355592ac8c2d28b085795b0faadf12531f119d4a1d15b1c7bcd45a5a661aad611799aa3286266469b88c12792bb4c3bba0b6c3fac2a0f54d
7
- data.tar.gz: 1a68d32efafe9ee2921ffd6c75a794dd340a4b6d814e4aa7daa6348fb1246644a12b99a071df7e7e1bfe84de02f15c96a4068f6227008ec051a1932b0bdb01db
6
+ metadata.gz: 9b3655be06b3aa59bdb700ba359f0dffd6bbe54840978665870673edb2e7249c179807b102cc7b49a503c638b0508a3cb46f0183afa4be7a8b8baff93b3dbab6
7
+ data.tar.gz: 36b999f281320ca0792e6504060eb65ba0f97005ed82b131dea276f6b136e6a0cca0281a3ab4a0c67ce213fe31e26263a1603bc7cf4ac10a847e264e64ccd512
@@ -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
@@ -35,11 +35,31 @@ module OoxmlParser
35
35
 
36
36
  full_path_to_file = OOXMLDocumentObject.path_to_folder + OOXMLDocumentObject.root_subfolder + @path.gsub('..', '')
37
37
  if File.exist?(full_path_to_file)
38
- @content = File.binread(full_path_to_file)
38
+ @content = if File.extname(@path) == '.xlsx'
39
+ parse_ole_xlsx(full_path_to_file)
40
+ else
41
+ File.binread(full_path_to_file)
42
+ end
39
43
  else
40
44
  warn "Couldn't find #{full_path_to_file} file on filesystem. Possible problem in original document"
41
45
  end
42
46
  self
43
47
  end
48
+
49
+ private
50
+
51
+ # Parse ole xlsx file
52
+ # @param [String] full_path to file
53
+ # @return [XLSXWorkbook]
54
+ def parse_ole_xlsx(full_path)
55
+ # TODO: Fix this ugly hack with global vars
56
+ # by replacing all global variables
57
+ stack = OOXMLDocumentObject.xmls_stack
58
+ dir = OOXMLDocumentObject.path_to_folder
59
+ result = OoxmlParser::Parser.parse(full_path)
60
+ OOXMLDocumentObject.xmls_stack = stack
61
+ OOXMLDocumentObject.path_to_folder = dir
62
+ result
63
+ end
44
64
  end
45
65
  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|
@@ -29,7 +29,7 @@ module OoxmlParser
29
29
  format = Parser.recognize_folder_format
30
30
  case format
31
31
  when :docx
32
- DocumentStructure.parse
32
+ DocumentStructure.new.parse
33
33
  when :xlsx
34
34
  XLSXWorkbook.new.parse
35
35
  when :pptx
@@ -21,8 +21,12 @@ module OoxmlParser
21
21
  attr_accessor :next_style
22
22
  # @return [DocxParagraphRun] run properties
23
23
  attr_accessor :run_properties
24
+ # @return [Nokogiri::XML:Node] run properties node
25
+ attr_accessor :run_properties_node
24
26
  # @return [DocxParagraph] run properties
25
27
  attr_accessor :paragraph_properties
28
+ # @return [Nokogiri::XML:Node] paragraph properties node
29
+ attr_accessor :paragraph_properties_node
26
30
  # @return [TableProperties] properties of table
27
31
  attr_accessor :table_properties
28
32
  # @return [Array, TableStyleProperties] list of table style properties
@@ -76,9 +80,11 @@ module OoxmlParser
76
80
  when 'next'
77
81
  @next_style = subnode.attribute('val').value
78
82
  when 'rPr'
79
- @run_properties = DocxParagraphRun.new(parent: self).parse_properties(subnode)
83
+ @run_properties_node = subnode
84
+ @run_properties = DocxParagraphRun.new(parent: self).parse_properties(@run_properties_node)
80
85
  when 'pPr'
81
- @paragraph_properties = ParagraphProperties.new(parent: self).parse(subnode)
86
+ @paragraph_properties_node = subnode
87
+ @paragraph_properties = ParagraphProperties.new(parent: self).parse(@paragraph_properties_node)
82
88
  when 'tblPr'
83
89
  @table_properties = TableProperties.new(parent: self).parse(subnode)
84
90
  when 'trPr'
@@ -12,7 +12,6 @@ require_relative 'docx_paragraph/inserted'
12
12
  require_relative 'docx_paragraph/structured_document_tag'
13
13
  require_relative 'docx_paragraph/frame_properties'
14
14
  require_relative 'docx_paragraph/docx_formula'
15
- require_relative 'docx_paragraph/style_parametres'
16
15
  module OoxmlParser
17
16
  # Class for data of DocxParagraph
18
17
  class DocxParagraph < OOXMLDocumentObject
@@ -202,7 +201,8 @@ module OoxmlParser
202
201
  when 'contextualSpacing'
203
202
  @contextual_spacing = true
204
203
  when 'pStyle'
205
- parse_paragraph_style_xml(node_child.attribute('val').value, default_char_style)
204
+ @paragraph_style_ref = ParagraphStyleRef.new(parent: self).parse(node_child)
205
+ fill_style_data(default_char_style)
206
206
  when 'ind'
207
207
  @ind = DocumentStructure.default_paragraph_style.ind.dup.parse(node_child)
208
208
  when 'numPr'
@@ -229,24 +229,13 @@ module OoxmlParser
229
229
  self
230
230
  end
231
231
 
232
- # Parse style xml
233
- # @param id [String] id of style to parse
232
+ # Fill data from styles
234
233
  # @param character_style [DocxParagraphRun] style to parse
235
234
  # @return [void]
236
- def parse_paragraph_style_xml(id, character_style)
237
- doc = parse_xml("#{OOXMLDocumentObject.path_to_folder}word/styles.xml")
238
- doc.search('//w:style').each do |style|
239
- next unless style.attribute('styleId').value == id
240
-
241
- style.xpath('w:pPr').each do |p_pr|
242
- parse_paragraph_style(p_pr, character_style)
243
- @style = StyleParametres.new(parent: self).parse(style)
244
- end
245
- style.xpath('w:rPr').each do |r_pr|
246
- character_style.parse_properties(r_pr)
247
- end
248
- break
249
- end
235
+ def fill_style_data(character_style)
236
+ @style = root_object.document_style_by_id(@paragraph_style_ref.value)
237
+ parse_paragraph_style(@style.paragraph_properties_node, character_style) if @style.paragraph_properties_node
238
+ character_style.parse_properties(@style.run_properties_node) if @style.run_properties_node
250
239
  end
251
240
 
252
241
  extend Gem::Deprecate
@@ -156,61 +156,60 @@ module OoxmlParser
156
156
 
157
157
  # Parse docx file
158
158
  # @return [DocumentStructure] parsed structure
159
- def self.parse
160
- doc_structure = DocumentStructure.new
161
- doc_structure.content_types = ContentTypes.new(parent: doc_structure).parse
159
+ def parse
160
+ @content_types = ContentTypes.new(parent: self).parse
162
161
  OOXMLDocumentObject.root_subfolder = 'word/'
163
162
  OOXMLDocumentObject.xmls_stack = []
164
163
  @comments = []
165
164
  DocumentStructure.default_paragraph_style = DocxParagraph.new
166
- DocumentStructure.default_run_style = DocxParagraphRun.new(parent: doc_structure)
167
- doc_structure.theme = PresentationTheme.parse('word/theme/theme1.xml')
168
- doc_structure.relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}word/_rels/document.xml.rels")
169
- doc_structure.parse_styles
165
+ DocumentStructure.default_run_style = DocxParagraphRun.new(parent: self)
166
+ @theme = PresentationTheme.parse('word/theme/theme1.xml')
167
+ @relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}word/_rels/document.xml.rels")
168
+ parse_styles
170
169
  number = 0
171
170
  OOXMLDocumentObject.add_to_xmls_stack('word/document.xml')
172
- doc = doc_structure.parse_xml(OOXMLDocumentObject.current_xml)
171
+ doc = parse_xml(OOXMLDocumentObject.current_xml)
173
172
  doc.search('//w:document').each do |document|
174
173
  document.xpath('w:background').each do |background|
175
- doc_structure.background = DocumentBackground.new(parent: doc_structure).parse(background)
174
+ @background = DocumentBackground.new(parent: self).parse(background)
176
175
  end
177
176
  document.xpath('w:body').each do |body|
178
177
  body.xpath('*').each do |element|
179
178
  case element.name
180
179
  when 'p'
181
180
  child = element.child
182
- unless child.nil? && doc_structure.elements.last.instance_of?(Table)
183
- paragraph_style = DocumentStructure.default_paragraph_style.dup.parse(element, number, DocumentStructure.default_run_style, parent: doc_structure)
181
+ unless child.nil? && @elements.last.instance_of?(Table)
182
+ paragraph_style = DocumentStructure.default_paragraph_style.dup.parse(element, number, DocumentStructure.default_run_style, parent: self)
184
183
  number += 1
185
- doc_structure.elements << paragraph_style.dup
184
+ @elements << paragraph_style.dup
186
185
  end
187
186
  when 'tbl'
188
- table = Table.new(parent: doc_structure).parse(element,
189
- number,
190
- TableProperties.new)
187
+ table = Table.new(parent: self).parse(element,
188
+ number,
189
+ TableProperties.new)
191
190
  number += 1
192
- doc_structure.elements << table
191
+ @elements << table
193
192
  when 'sdt'
194
- doc_structure.elements << StructuredDocumentTag.new(parent: doc_structure).parse(element)
193
+ @elements << StructuredDocumentTag.new(parent: self).parse(element)
195
194
  end
196
195
  end
197
196
  body.xpath('w:sectPr').each do |sect_pr|
198
- doc_structure.page_properties = PageProperties.new(parent: doc_structure).parse(sect_pr,
199
- DocumentStructure.default_paragraph_style,
200
- DocumentStructure.default_run_style)
201
- doc_structure.notes = doc_structure.page_properties.notes # keep copy of notes to compatibility with previous docx models
197
+ @page_properties = PageProperties.new(parent: self).parse(sect_pr,
198
+ DocumentStructure.default_paragraph_style,
199
+ DocumentStructure.default_run_style)
200
+ @notes = page_properties.notes # keep copy of notes to compatibility with previous docx models
202
201
  end
203
202
  end
204
203
  end
205
204
  OOXMLDocumentObject.xmls_stack.pop
206
- doc_structure.document_properties = DocumentProperties.new(parent: doc_structure).parse
207
- doc_structure.comments = Comments.new(parent: doc_structure).parse
208
- doc_structure.comments_extended = CommentsExtended.new(parent: doc_structure).parse
209
- doc_structure.comments_document = Comments.new(parent: doc_structure,
210
- file: "#{OOXMLDocumentObject.path_to_folder}word/#{doc_structure.relationships.target_by_type('commentsDocument').first}")
211
- .parse
212
- doc_structure.settings = DocumentSettings.new(parent: doc_structure).parse
213
- doc_structure
205
+ @document_properties = DocumentProperties.new(parent: self).parse
206
+ @comments = Comments.new(parent: self).parse
207
+ @comments_extended = CommentsExtended.new(parent: self).parse
208
+ @comments_document = Comments.new(parent: self,
209
+ file: "#{OOXMLDocumentObject.path_to_folder}word/#{relationships.target_by_type('commentsDocument').first}")
210
+ .parse
211
+ @settings = DocumentSettings.new(parent: self).parse
212
+ self
214
213
  end
215
214
 
216
215
  # Parse default style
@@ -11,7 +11,7 @@ module OoxmlParser
11
11
  # @return [DocumentStructure] result of parse
12
12
  def self.parse_docx(path_to_file)
13
13
  Parser.parse_format(path_to_file) do
14
- DocumentStructure.parse
14
+ DocumentStructure.new.parse
15
15
  end
16
16
  end
17
17
  end
@@ -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.29.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.29.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-09-05 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
@@ -420,7 +423,6 @@ files:
420
423
  - lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_content.rb
421
424
  - lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/sdt/sdt_properties.rb
422
425
  - lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/structured_document_tag.rb
423
- - lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/style_parametres.rb
424
426
  - lib/ooxml_parser/docx_parser/document_structure/header_footer.rb
425
427
  - lib/ooxml_parser/docx_parser/document_structure/numbering.rb
426
428
  - lib/ooxml_parser/docx_parser/document_structure/numbering/abstract_numbering.rb
@@ -605,7 +607,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
605
607
  - !ruby/object:Gem::Version
606
608
  version: '0'
607
609
  requirements: []
608
- rubygems_version: 3.3.20
610
+ rubygems_version: 3.3.21
609
611
  signing_key:
610
612
  specification_version: 4
611
613
  summary: OoxmlParser Gem
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OoxmlParser
4
- # Style Parameter Data
5
- class StyleParametres < OOXMLDocumentObject
6
- attr_accessor :q_format, :hidden, :name
7
-
8
- def initialize(params = {})
9
- @name = params[:name]
10
- @q_format = params.fetch(:q_format, false)
11
- @hidden = params.fetch(:hidden, false)
12
- super(parent: params[:parent])
13
- end
14
-
15
- # Parse StyleParametres data
16
- # @param [Nokogiri::XML:Element] node with StyleParametres data
17
- # @return [StyleParametres] value of Columns data
18
- def parse(node)
19
- node.xpath('*').each do |node_child|
20
- case node_child.name
21
- when 'name'
22
- @name = node_child.attribute('val').value
23
- when 'qFormat'
24
- @q_format = option_enabled?(node_child)
25
- end
26
- end
27
- self
28
- end
29
- end
30
- end