ooxml_parser 0.25.0 → 0.28.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: 409ce77d24b38512604d5215a2bd6a54f887685db71cd9942c81935ef678f3b0
4
- data.tar.gz: 4f7edddf4bab2d5d6ab9485754b333a2943d2df96fdcc933d671e820cd9dc70d
3
+ metadata.gz: ddd7d84f5f19a2b12fad76d455ebc614f9eb1b7a5c6f96f3585e649dc2569c4a
4
+ data.tar.gz: ca87a76367cb58ed7d02c7be6bcdb2ffe1e6635cccccff5a5ca33f44e44ed60b
5
5
  SHA512:
6
- metadata.gz: aad06b0a4dd775d5efe4411d43b87ebda68fe05a5a15924fb6773d77169141284baaf8047eee042634a2e6145649ac0fce2e9aa143d401587434598eeff5f73d
7
- data.tar.gz: c2ab404a2ab3f559a312da5953da7a668b4ae1c359ff790bc4b4d577ccbd453e4314844125cc64e144c884f9e187389586c98f085c4d27ca5837d8a1b9e61f9d
6
+ metadata.gz: 8e85e11b6a5faf18784cc9f3e9b216a1aad962aaf2be54f6dc35d1e3c8fbb73e9b4ed86270e796f01260fcdf2404729c2a36b5b9d133020916f142e12f32b903
7
+ data.tar.gz: 5e3c2129a515ce309a33e5f8c75847cde732a6ce4108f36bb8c3222d3b02f48b42bef3faa9eecaafc063f691e58d39e020f1eda3e44767b9452813ab8d3ca087
@@ -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
@@ -4,6 +4,16 @@ module OoxmlParser
4
4
  # Docx Wrap Drawing
5
5
  class DocxWrapDrawing < OOXMLDocumentObject
6
6
  attr_accessor :wrap_text, :distance_from_text
7
+ # @return [Boolean] Specifies whether this floating DrawingML
8
+ # object is displayed behind the text of the
9
+ # document when the document is displayed.
10
+ # When a DrawingML object is displayed
11
+ # within a WordprocessingML document,
12
+ # that object can intersect with text in the
13
+ # document. This attribute shall determine
14
+ # whether the text or the object is rendered on
15
+ # top in case of overlapping.
16
+ attr_reader :behind_doc
7
17
 
8
18
  def initialize(parent: nil)
9
19
  @wrap_text = :none
@@ -14,10 +24,16 @@ module OoxmlParser
14
24
  # @param node [Nokogiri::XML:Element] node to parse
15
25
  # @return [DocxWrapDrawing] result of parsing
16
26
  def parse(node)
17
- unless node.attribute('behindDoc').nil?
18
- @wrap_text = :behind if node.attribute('behindDoc').value == '1'
19
- @wrap_text = :infront if node.attribute('behindDoc').value == '0'
27
+ node.attributes.each do |key, value|
28
+ case key
29
+ when 'behindDoc'
30
+ @behind_doc = attribute_enabled?(value)
31
+ end
20
32
  end
33
+
34
+ @wrap_text = :behind if @behind_doc == true
35
+ @wrap_text = :infront if @behind_doc == false
36
+
21
37
  node.xpath('*').each do |node_child|
22
38
  case node_child.name
23
39
  when 'wrapSquare'
@@ -35,7 +35,11 @@ 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
+ OoxmlParser::Parser.parse(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
@@ -60,8 +60,10 @@ module OoxmlParser
60
60
  to_s
61
61
  end
62
62
 
63
- # @return [String] color in hex value
63
+ # @return [String, nil] color in hex value or `nil` if color is not defined
64
64
  def to_hex
65
+ return nil if none?
66
+
65
67
  (@red.to_s(16).rjust(2, '0') + @green.to_s(16).rjust(2, '0') + @blue.to_s(16).rjust(2, '0')).upcase
66
68
  end
67
69
 
@@ -154,7 +156,10 @@ module OoxmlParser
154
156
  # @param scheme_color_node [Nokogiri::XML:Element] node to parse
155
157
  # @return [Color] result of parsing
156
158
  def parse_scheme_color(scheme_color_node)
157
- 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
158
163
  hls = color.to_hsl
159
164
  scheme_name = nil
160
165
  scheme_color_node.xpath('*').each do |scheme_color_node_child|
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # noinspection RubyTooManyInstanceVariablesInspection
4
3
  require_relative 'docx_paragraph_run/docx_paragraph_run_helpers'
5
4
  require_relative 'docx_paragraph_run/instruction_text'
6
5
  require_relative 'docx_paragraph_run/object'
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # noinspection RubyTooManyInstanceVariablesInspection
4
3
  require_relative 'docx_paragraph/bookmark_start'
5
4
  require_relative 'docx_paragraph/bookmark_end'
6
5
  require_relative 'docx_paragraph/comment_range_end'
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # noinspection RubyInstanceMethodNamingConvention
4
3
  require_relative 'document_structure/comments'
5
4
  require_relative 'document_structure/comments_extended'
6
5
  require_relative 'document_structure/docx_paragraph'
@@ -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.25.0'
7
+ STRING = '0.28.0'
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
  module OoxmlParser
4
4
  # Properties of XLSX column
5
5
  class XlsxColumnProperties < OOXMLDocumentObject
6
- attr_accessor :from, :to, :width, :style
6
+ attr_accessor :style
7
7
  # @return [True, False] is width custom
8
8
  attr_accessor :custom_width
9
9
  # @return [True, False] Flag indicating if the
@@ -12,6 +12,14 @@ module OoxmlParser
12
12
  # @return [True, False] Flag indicating if the
13
13
  # specified column(s) is hidden
14
14
  attr_reader :hidden
15
+ # @return [Integer] First column affected by this 'column info' record.
16
+ attr_reader :min
17
+ # @return [Integer] Last column affected by this 'column info' record.
18
+ attr_reader :max
19
+ # @return [Float] width in pixel, as stored in xml structure
20
+ attr_reader :width_raw
21
+ # @return [Float] width, in readable format
22
+ attr_reader :width
15
23
 
16
24
  # Parse XlsxColumnProperties object
17
25
  # @param node [Nokogiri::XML:Element] node to parse
@@ -20,13 +28,14 @@ module OoxmlParser
20
28
  node.attributes.each do |key, value|
21
29
  case key
22
30
  when 'min'
23
- @from = value.value.to_i
31
+ @min = value.value.to_i
24
32
  when 'max'
25
- @to = value.value.to_i
33
+ @max = value.value.to_i
26
34
  when 'style'
27
35
  @style = root_object.style_sheet.cell_xfs.xf_array[value.value.to_i]
28
36
  when 'width'
29
- @width = value.value.to_f - 0.7109375
37
+ @width_raw = value.value.to_f
38
+ @width = calculate_width(@width_raw)
30
39
  when 'customWidth'
31
40
  @custom_width = option_enabled?(node, 'customWidth')
32
41
  when 'bestFit'
@@ -38,6 +47,13 @@ module OoxmlParser
38
47
  self
39
48
  end
40
49
 
50
+ alias from min
51
+ alias to max
52
+
53
+ extend Gem::Deprecate
54
+ deprecate :from, 'min', 2099, 1
55
+ deprecate :to, 'max', 2099, 1
56
+
41
57
  # Parse list of XlsxColumnProperties
42
58
  # @param columns_width_node [Nokogiri::XML:Element] node to parse
43
59
  # @param parent [OOXMLDocumentObject] parent of result objects
@@ -50,5 +66,17 @@ module OoxmlParser
50
66
  end
51
67
  columns
52
68
  end
69
+
70
+ private
71
+
72
+ # TODO: Currently width calculation use some magick number from old time ago
73
+ # Actual formula is way more complicated and require data about
74
+ # font max width for single character.
75
+ # Read more in ECMA-376, §18.3.1.13
76
+ # @param [Float] value raw value for width
77
+ # @return [Float] width value
78
+ def calculate_width(value)
79
+ value - 0.7109375
80
+ end
53
81
  end
54
82
  end
@@ -12,6 +12,8 @@ module OoxmlParser
12
12
  attr_reader :style_index
13
13
  # @return [String] value of cell
14
14
  attr_reader :value
15
+ # @return [String] An A-1 style reference to a cell.
16
+ attr_reader :reference
15
17
  # @return [String] type of string
16
18
  attr_reader :type
17
19
 
@@ -31,6 +33,8 @@ module OoxmlParser
31
33
  @style_index = value.value.to_i
32
34
  when 't'
33
35
  @type = value.value.to_s
36
+ when 'r'
37
+ @reference = value.value.to_s
34
38
  end
35
39
  end
36
40
  node.xpath('*').each do |node_child|
@@ -60,6 +64,11 @@ module OoxmlParser
60
64
  @raw_text
61
65
  end
62
66
 
67
+ # @return [Coordinates] coordinates of cell
68
+ def coordinates
69
+ @coordinates ||= Coordinates.new.parse_string(@reference)
70
+ end
71
+
63
72
  private
64
73
 
65
74
  # @return [Nothing] parse text data
@@ -4,13 +4,19 @@ require_relative 'xlsx_row/xlsx_cell'
4
4
  module OoxmlParser
5
5
  # Single Row of XLSX
6
6
  class XlsxRow < OOXMLDocumentObject
7
- attr_accessor :cells, :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
- # @return [Integer] Indicates to which row in the sheet this <row> definition corresponds.
10
+ # @return [Integer] Indicates to which row in the sheet
11
+ # this <row> definition corresponds.
11
12
  attr_accessor :index
13
+ # @return [Array<Cells>] cells of row, as in xml structure
14
+ attr_reader :cells_raw
15
+ # @return [Integer] index of style of row
16
+ attr_reader :style_index
12
17
 
13
18
  def initialize(parent: nil)
19
+ @cells_raw = []
14
20
  @cells = []
15
21
  super
16
22
  end
@@ -29,15 +35,36 @@ module OoxmlParser
29
35
  @hidden = option_enabled?(node, 'hidden')
30
36
  when 'r'
31
37
  @index = value.value.to_i
38
+ when 's'
39
+ @style_index = value.value.to_i
32
40
  end
33
41
  end
34
42
  node.xpath('*').each do |node_child|
35
43
  case node_child.name
36
44
  when 'c'
37
- @cells[Coordinates.new.parse_string(node_child.attribute('r').value.to_s).column_number.to_i - 1] = XlsxCell.new(parent: self).parse(node_child)
45
+ @cells_raw << XlsxCell.new(parent: self).parse(node_child)
38
46
  end
39
47
  end
40
48
  self
41
49
  end
50
+
51
+ # @return [Array<XlsxCell, nil>] list of cell in row, with nil,
52
+ # if cell data is not stored in xml
53
+ def cells
54
+ return @cells if @cells.any?
55
+
56
+ cells_raw.each do |cell|
57
+ @cells[cell.coordinates.column_number.to_i - 1] = cell
58
+ end
59
+
60
+ @cells
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
42
69
  end
43
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.25.0
4
+ version: 0.28.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-07-28 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
@@ -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.19
611
+ rubygems_version: 3.3.21
609
612
  signing_key:
610
613
  specification_version: 4
611
614
  summary: OoxmlParser Gem