ooxml_parser 0.24.0 → 0.27.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 +4 -4
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/chart_style_file/chart_style_entry.rb +46 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/chart_style_file/marker_layout.rb +26 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/chart_style_file.rb +144 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +33 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_wrap_drawing.rb +19 -3
- data/lib/ooxml_parser/common_parser/common_data/color.rb +7 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_spacing.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +5 -5
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/instruction_text.rb +22 -0
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb +8 -8
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/indents.rb +1 -1
- data/lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb +1 -6
- data/lib/ooxml_parser/docx_parser/document_structure.rb +0 -1
- data/lib/ooxml_parser/pptx_parser/presentation.rb +2 -3
- data/lib/ooxml_parser/version.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_column_properties.rb +32 -4
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row/xlsx_cell.rb +9 -0
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet/xlsx_row.rb +30 -3
- data/lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb +19 -7
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a5fdd9341474bc26ce030d37d3fbdfd75cf940c045d463e512c8e5fbb13f17a
|
4
|
+
data.tar.gz: 91205544439de08e01535cee8846b365c8d605d5cea03421ff143a4cb888723a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/chart_style_file.rb
ADDED
@@ -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
|
-
|
18
|
-
|
19
|
-
|
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'
|
@@ -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
|
-
|
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|
|
data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_spacing.rb
CHANGED
@@ -38,8 +38,8 @@ module OoxmlParser
|
|
38
38
|
private
|
39
39
|
|
40
40
|
# This is dirty workaround for situations
|
41
|
-
# Then
|
42
|
-
#
|
41
|
+
# Then `@line_rule` parsed after `@line` so getting
|
42
|
+
# `@line` value is totally screwed up
|
43
43
|
# @param [Nokogiri::XML:Node] node with ParagraphSpacing
|
44
44
|
# @return [Hash] hash with sorted values
|
45
45
|
# TODO: Totally redone parsing of spacing to remove this workaround
|
@@ -8,11 +8,11 @@ module OoxmlParser
|
|
8
8
|
|
9
9
|
# @return [String] result of convert of object to string
|
10
10
|
def to_s
|
11
|
-
"Table position left: #{left}, "\
|
12
|
-
"right: #{right}, "\
|
13
|
-
"top: #{top}, "\
|
14
|
-
"bottom #{bottom}, "\
|
15
|
-
"position x: #{position_x}, "\
|
11
|
+
"Table position left: #{left}, " \
|
12
|
+
"right: #{right}, " \
|
13
|
+
"top: #{top}, " \
|
14
|
+
"bottom #{bottom}, " \
|
15
|
+
"position x: #{position_x}, " \
|
16
16
|
"position y: #{position_y}"
|
17
17
|
end
|
18
18
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for parsing `w:instrText` object
|
5
|
+
class InstructionText < TextValue
|
6
|
+
# @return [Boolean] is current object for hyperlink
|
7
|
+
def hyperlink?
|
8
|
+
value.include?('HYPERLINK')
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Boolean] is current object for page number
|
12
|
+
def page_number?
|
13
|
+
value.match?(/PAGE\s+\\\*/)
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Hyperlink] convert InstructionText to Hyperlink
|
17
|
+
def to_hyperlink
|
18
|
+
Hyperlink.new(value.sub('HYPERLINK ', '').split(' \\o ').first,
|
19
|
+
value.sub('HYPERLINK', '').split(' \\o ').last)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# noinspection RubyTooManyInstanceVariablesInspection
|
4
3
|
require_relative 'docx_paragraph_run/docx_paragraph_run_helpers'
|
4
|
+
require_relative 'docx_paragraph_run/instruction_text'
|
5
5
|
require_relative 'docx_paragraph_run/object'
|
6
6
|
require_relative 'docx_paragraph_run/text_outline'
|
7
7
|
require_relative 'docx_paragraph_run/text_fill'
|
@@ -15,9 +15,9 @@ module OoxmlParser
|
|
15
15
|
:link, :highlight, :effect, :caps, :w,
|
16
16
|
:position, :em, :spacing, :break, :touch, :shape, :footnote, :endnote, :fld_char, :style,
|
17
17
|
:comments, :alternate_content, :page_number, :text_outline, :text_fill
|
18
|
-
# @return [
|
19
|
-
#
|
20
|
-
|
18
|
+
# @return [InstructionText] text of instruction
|
19
|
+
# See ECMA-376, 17.16.23 instrText (Field Code)
|
20
|
+
attr_reader :instruction_text
|
21
21
|
# @return [RunProperties] properties of run
|
22
22
|
attr_accessor :run_properties
|
23
23
|
# @return [RunObject] object of run
|
@@ -96,10 +96,10 @@ module OoxmlParser
|
|
96
96
|
parse_properties(node_child)
|
97
97
|
@run_properties = RunProperties.new(parent: self).parse(node_child)
|
98
98
|
when 'instrText'
|
99
|
-
|
100
|
-
|
101
|
-
@link =
|
102
|
-
elsif
|
99
|
+
@instruction_text = InstructionText.new(parent: self).parse(node_child)
|
100
|
+
if @instruction_text.hyperlink?
|
101
|
+
@link = @instruction_text.to_hyperlink
|
102
|
+
elsif @instruction_text.page_number?
|
103
103
|
@text = '*PAGE NUMBER*'
|
104
104
|
end
|
105
105
|
when 'fldChar'
|
@@ -25,7 +25,7 @@ module OoxmlParser
|
|
25
25
|
# Convert to string
|
26
26
|
# @return [String] result of conversion
|
27
27
|
def to_s
|
28
|
-
"first line indent: #{@first_line_indent}, left indent: #{@left_indent}, "\
|
28
|
+
"first line indent: #{@first_line_indent}, left indent: #{@left_indent}, " \
|
29
29
|
"right indent: #{@right_indent}, hanging indent: #{@hanging_indent}"
|
30
30
|
end
|
31
31
|
|
@@ -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'
|
@@ -18,7 +17,7 @@ module OoxmlParser
|
|
18
17
|
# Class for data of DocxParagraph
|
19
18
|
class DocxParagraph < OOXMLDocumentObject
|
20
19
|
include DocxParagraphHelper
|
21
|
-
attr_accessor :number, :
|
20
|
+
attr_accessor :number, :align, :spacing, :ind, :numbering,
|
22
21
|
:character_style_array, :page_break, :borders, :keep_lines,
|
23
22
|
:contextual_spacing, :sector_properties, :page_numbering, :section_break, :style, :keep_next,
|
24
23
|
:orphan_control
|
@@ -39,8 +38,6 @@ module OoxmlParser
|
|
39
38
|
|
40
39
|
def initialize(parent: nil)
|
41
40
|
@number = 0
|
42
|
-
@bookmark_start = []
|
43
|
-
@bookmark_end = []
|
44
41
|
@align = :left
|
45
42
|
@spacing = Spacing.new
|
46
43
|
@ind = Indents.new
|
@@ -62,8 +59,6 @@ module OoxmlParser
|
|
62
59
|
# @return [void]
|
63
60
|
def initialize_copy(source)
|
64
61
|
super
|
65
|
-
@bookmark_start = source.bookmark_start.clone
|
66
|
-
@bookmark_end = source.bookmark_end.clone
|
67
62
|
@character_style_array = source.character_style_array.clone
|
68
63
|
@spacing = source.spacing.clone
|
69
64
|
end
|
@@ -58,10 +58,9 @@ module OoxmlParser
|
|
58
58
|
@slide_size = SlideSize.new(parent: self).parse(presentation_node_child)
|
59
59
|
when 'sldIdLst'
|
60
60
|
presentation_node_child.xpath('p:sldId').each do |silde_id_node|
|
61
|
-
|
62
|
-
silde_id_node.attribute_nodes.select { |node| id = node.to_s if node.namespace && node.namespace.prefix == 'r' }
|
61
|
+
slide_id = silde_id_node.attr('r:id')
|
63
62
|
@slides << Slide.new(parent: self,
|
64
|
-
xml_path: "#{OOXMLDocumentObject.root_subfolder}/#{OOXMLDocumentObject.get_link_from_rels(
|
63
|
+
xml_path: "#{OOXMLDocumentObject.root_subfolder}/#{OOXMLDocumentObject.get_link_from_rels(slide_id)}")
|
65
64
|
.parse
|
66
65
|
end
|
67
66
|
end
|
data/lib/ooxml_parser/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Properties of XLSX column
|
5
5
|
class XlsxColumnProperties < OOXMLDocumentObject
|
6
|
-
attr_accessor :
|
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
|
-
@
|
31
|
+
@min = value.value.to_i
|
24
32
|
when 'max'
|
25
|
-
@
|
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
|
-
@
|
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 :
|
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
|
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
|
-
@
|
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, :
|
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 @
|
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
|
-
@
|
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
|
-
|
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.
|
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-
|
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
|
@@ -403,6 +406,7 @@ files:
|
|
403
406
|
- lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_helper.rb
|
404
407
|
- lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run.rb
|
405
408
|
- lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb
|
409
|
+
- lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/instruction_text.rb
|
406
410
|
- lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/object.rb
|
407
411
|
- lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/object/ole_object.rb
|
408
412
|
- lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/docx_paragraph_run/shape.rb
|
@@ -604,7 +608,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
604
608
|
- !ruby/object:Gem::Version
|
605
609
|
version: '0'
|
606
610
|
requirements: []
|
607
|
-
rubygems_version: 3.3.
|
611
|
+
rubygems_version: 3.3.21
|
608
612
|
signing_key:
|
609
613
|
specification_version: 4
|
610
614
|
summary: OoxmlParser Gem
|