ooxml_parser 0.22.0 → 0.23.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/drawing/graphic/shape/docx_shape/shape_style/{effect_reference.rb → style_matrix_reference.rb} +4 -4
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style.rb +4 -6
- data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +30 -21
- data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +0 -23
- data/lib/ooxml_parser/common_parser/parser/encryption_checker.rb +43 -0
- data/lib/ooxml_parser/common_parser/parser.rb +3 -1
- data/lib/ooxml_parser/version.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/pane.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/selection.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb +1 -1
- metadata +6 -21
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/fill_reference.rb +0 -31
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/line_reference.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a21fe67d2c235a37ec324fcd56428e39ff519f9a4f36b7c8257770b135922eec
|
4
|
+
data.tar.gz: c6ce18f4dd16cfc0d484ad0391b8787dbe7ba226b4fd744b5c44d7d4ac2e9f6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d926a20fbd8fd1e855983994f0b7e707c3d5d603247fc3b3c4bcd8e680febb19b4cf3232bc68dd3f4c55852bb342d195a62f9af875ab6ad1a69a9f86668e38d8
|
7
|
+
data.tar.gz: 789f9064bbd3d17a21d6d01a9e39d8203a59f622cb2ce48e09de62dadec00e16e9ca9d38f5ebc56ff53920f7c00874077ce4d5358975844c25c14e494075c0d7
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module OoxmlParser
|
4
|
-
# Class for parsing `a:effectRef` tags
|
5
|
-
class
|
4
|
+
# Class for parsing `a:fillRef`, `a:effectRef`, `a:lnRef` tags
|
5
|
+
class StyleMatrixReference < OOXMLDocumentObject
|
6
6
|
# @return [Integer] Style Matrix Index
|
7
7
|
attr_reader :index
|
8
8
|
# @return [Color] scheme color of EffectReference
|
9
9
|
attr_reader :scheme_color
|
10
10
|
|
11
|
-
# Parse
|
11
|
+
# Parse StyleMatrixReference object
|
12
12
|
# @param node [Nokogiri::XML:Element] node to parse
|
13
|
-
# @return [
|
13
|
+
# @return [StyleMatrixReference] result of parsing
|
14
14
|
def parse(node)
|
15
15
|
node.attributes.each do |key, value|
|
16
16
|
case key
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'shape_style/
|
4
|
-
require_relative 'shape_style/fill_reference'
|
3
|
+
require_relative 'shape_style/style_matrix_reference'
|
5
4
|
require_relative 'shape_style/font_reference'
|
6
|
-
require_relative 'shape_style/line_reference'
|
7
5
|
module OoxmlParser
|
8
6
|
# Class for parsing `wps:style` tags
|
9
7
|
class ShapeStyle < OOXMLDocumentObject
|
@@ -23,13 +21,13 @@ module OoxmlParser
|
|
23
21
|
node.xpath('*').each do |node_child|
|
24
22
|
case node_child.name
|
25
23
|
when 'effectRef'
|
26
|
-
@effect_reference =
|
24
|
+
@effect_reference = StyleMatrixReference.new(parent: self).parse(node_child)
|
27
25
|
when 'fillRef'
|
28
|
-
@fill_reference =
|
26
|
+
@fill_reference = StyleMatrixReference.new(parent: self).parse(node_child)
|
29
27
|
when 'fontRef'
|
30
28
|
@font_reference = FontReference.new(parent: self).parse(node_child)
|
31
29
|
when 'lnRef'
|
32
|
-
@line_reference =
|
30
|
+
@line_reference = StyleMatrixReference.new(parent: self).parse(node_child)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
self
|
@@ -12,23 +12,6 @@ module OoxmlParser
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class << self
|
15
|
-
# @param [String] string to parse
|
16
|
-
# @return [Coordinates]
|
17
|
-
def parse_coordinates_from_string(string)
|
18
|
-
coordinates = Coordinates.new
|
19
|
-
begin
|
20
|
-
coordinates.list = string.match(/'\w+'/)[0].delete("''")
|
21
|
-
rescue StandardError
|
22
|
-
'Raise Exception'
|
23
|
-
end
|
24
|
-
string = string.split('!').last
|
25
|
-
if coordinates?(string)
|
26
|
-
coordinates.row = string.scan(/[0-9]/).join.to_i
|
27
|
-
coordinates.column = string.scan(/[A-Z]/).join
|
28
|
-
end
|
29
|
-
coordinates
|
30
|
-
end
|
31
|
-
|
32
15
|
# Parse range of coordinates
|
33
16
|
# @param arguments_string [String] data to parse
|
34
17
|
# @return [Array] result
|
@@ -109,6 +92,18 @@ module OoxmlParser
|
|
109
92
|
end
|
110
93
|
end
|
111
94
|
|
95
|
+
# Parse string to coordinates
|
96
|
+
# @param [String] string to parse
|
97
|
+
# @return [Coordinates] result
|
98
|
+
def parse_string(string)
|
99
|
+
string = extract_list_from_string(string) if list_name_in_string?(string)
|
100
|
+
if Coordinates.coordinates?(string)
|
101
|
+
@row = string.scan(/\d/).join.to_i
|
102
|
+
@column = string.scan(/[A-Z]/).join
|
103
|
+
end
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
112
107
|
# @return [Integer] number of column
|
113
108
|
# This method takes @column string
|
114
109
|
# and converts into integer
|
@@ -118,10 +113,6 @@ module OoxmlParser
|
|
118
113
|
end
|
119
114
|
end
|
120
115
|
|
121
|
-
alias get_column_number column_number
|
122
|
-
extend Gem::Deprecate
|
123
|
-
deprecate :get_column_number, 'column_number', 2020, 1
|
124
|
-
|
125
116
|
# Compares rows of two cells
|
126
117
|
# @param [Coordinates] other_cell other cell coordinates
|
127
118
|
# @return [true, false] true, if row greater, than other row
|
@@ -151,5 +142,23 @@ module OoxmlParser
|
|
151
142
|
def ==(other)
|
152
143
|
other.is_a?(Coordinates) ? (@row == other.row && @column == other.column) : false
|
153
144
|
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
# Check if there is list name in string
|
149
|
+
# @param [String] string to check
|
150
|
+
# @return [Boolean] result
|
151
|
+
def list_name_in_string?(string)
|
152
|
+
string.include?('!')
|
153
|
+
end
|
154
|
+
|
155
|
+
# Extract list name and leave coordinates
|
156
|
+
# @param [String] string to parse
|
157
|
+
# @return [String] coordinates string without list
|
158
|
+
def extract_list_from_string(string)
|
159
|
+
split = string.split('!')
|
160
|
+
@list = split[0...-1].join('!')
|
161
|
+
split[-1]
|
162
|
+
end
|
154
163
|
end
|
155
164
|
end
|
@@ -43,14 +43,14 @@ module OoxmlParser
|
|
43
43
|
node.attributes.each do |key, value|
|
44
44
|
case key
|
45
45
|
when 'location'
|
46
|
-
@url = Coordinates.
|
46
|
+
@url = Coordinates.new.parse_string(value.value)
|
47
47
|
when 'id'
|
48
48
|
@id = value.value
|
49
49
|
@url = OOXMLDocumentObject.get_link_from_rels(@id) unless @id.empty?
|
50
50
|
when 'tooltip'
|
51
51
|
@tooltip = value.value
|
52
52
|
when 'ref'
|
53
|
-
@coordinates = Coordinates.
|
53
|
+
@coordinates = Coordinates.new.parse_string(value.value)
|
54
54
|
when 'action'
|
55
55
|
@action_link = value.value
|
56
56
|
when 'highlightClick'
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'filemagic' unless Gem.win_platform?
|
4
3
|
require 'securerandom'
|
5
4
|
require 'nokogiri'
|
6
5
|
require 'zip'
|
@@ -59,28 +58,6 @@ module OoxmlParser
|
|
59
58
|
# @return [String] path to root folder
|
60
59
|
attr_accessor :path_to_folder
|
61
60
|
|
62
|
-
# @param path_to_file [String] file
|
63
|
-
# @param ignore_system [True, False] should host system be ignored, since
|
64
|
-
# this method is OS-dependent
|
65
|
-
# @return [True, False] Check if file is protected by password on open
|
66
|
-
def encrypted_file?(path_to_file, ignore_system: false)
|
67
|
-
if Gem.win_platform? || ignore_system
|
68
|
-
warn 'FileMagic and checking file for encryption is not supported on Windows'
|
69
|
-
return false
|
70
|
-
end
|
71
|
-
file_result = FileMagic.new(:mime).file(path_to_file)
|
72
|
-
# Support of Encrtypted status in `file` util was introduced in file v5.20
|
73
|
-
# but LTS version of ubuntu before 16.04 uses older `file` and it return `Composite Document`
|
74
|
-
# https://github.com/file/file/blob/master/ChangeLog#L217
|
75
|
-
if file_result.include?('encrypted') ||
|
76
|
-
file_result.include?('Composite Document File V2 Document, No summary info') ||
|
77
|
-
file_result.include?('application/CDFV2-corrupt')
|
78
|
-
warn("File #{path_to_file} is encrypted. Can't parse it")
|
79
|
-
return true
|
80
|
-
end
|
81
|
-
false
|
82
|
-
end
|
83
|
-
|
84
61
|
# Copy this file and rename to zip
|
85
62
|
# @param path [String] path to file
|
86
63
|
# @return [String] path to result zip
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Check if file is encrypted
|
5
|
+
class EncryptionChecker
|
6
|
+
def initialize(file_path, ignore_system: false)
|
7
|
+
@file_path = file_path
|
8
|
+
@ignore_system = ignore_system
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Boolean] is file encrypted
|
12
|
+
def encrypted?
|
13
|
+
return false unless compatible_system?
|
14
|
+
|
15
|
+
# Support of Encrypted status in `file` util was introduced in file v5.20
|
16
|
+
# but LTS version of ubuntu before 16.04 uses older `file` and it return `Composite Document`
|
17
|
+
# https://github.com/file/file/blob/0eb7c1b83341cc954620b45d2e2d65ee7df1a4e7/ChangeLog#L623
|
18
|
+
if mime_type.include?('encrypted') ||
|
19
|
+
mime_type.include?('Composite Document File V2 Document, No summary info') ||
|
20
|
+
mime_type.include?('application/CDFV2-corrupt')
|
21
|
+
warn("File #{@file_path} is encrypted. Can't parse it")
|
22
|
+
return true
|
23
|
+
end
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Check if system is compatible with `file` utility
|
30
|
+
# @return [Boolean] Result of check
|
31
|
+
def compatible_system?
|
32
|
+
return true if !Gem.win_platform? && !@ignore_system
|
33
|
+
|
34
|
+
warn 'Checking file for encryption is not supported on Windows'
|
35
|
+
false
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [String] mime type of file
|
39
|
+
def mime_type
|
40
|
+
@mime_type ||= `file -b --mime "#{@file_path}"`
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'parser/encryption_checker'
|
4
|
+
|
3
5
|
module OoxmlParser
|
4
6
|
# Basic class for OoxmlParser
|
5
7
|
class Parser
|
@@ -7,7 +9,7 @@ module OoxmlParser
|
|
7
9
|
# @param path_to_file [String] file
|
8
10
|
# @return [CommonDocumentStructure] structure of doc
|
9
11
|
def self.parse_format(path_to_file)
|
10
|
-
return nil if
|
12
|
+
return nil if EncryptionChecker.new(path_to_file).encrypted?
|
11
13
|
|
12
14
|
path_to_zip_file = OOXMLDocumentObject.copy_file_and_rename_to_zip(path_to_file)
|
13
15
|
OOXMLDocumentObject.path_to_folder = path_to_zip_file.sub(File.basename(path_to_zip_file), '')
|
data/lib/ooxml_parser/version.rb
CHANGED
data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/pane.rb
CHANGED
@@ -14,7 +14,7 @@ module OoxmlParser
|
|
14
14
|
when 'state'
|
15
15
|
@state = value.value.to_sym
|
16
16
|
when 'topLeftCell'
|
17
|
-
@top_left_cell = Coordinates.
|
17
|
+
@top_left_cell = Coordinates.new.parse_string(value.value)
|
18
18
|
when 'xSplit'
|
19
19
|
@x_split = value.value
|
20
20
|
when 'ySplit'
|
data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/selection.rb
CHANGED
@@ -17,7 +17,7 @@ module OoxmlParser
|
|
17
17
|
node.attributes.each do |key, value|
|
18
18
|
case key
|
19
19
|
when 'activeCell'
|
20
|
-
@active_cell = Coordinates.
|
20
|
+
@active_cell = Coordinates.new.parse_string(value.value)
|
21
21
|
when 'activeCellId'
|
22
22
|
@active_cell_id = value.value.to_i
|
23
23
|
when 'sqref'
|
@@ -36,7 +36,7 @@ module OoxmlParser
|
|
36
36
|
when 'showRowColHeaders'
|
37
37
|
@show_row_column_headers = attribute_enabled?(value)
|
38
38
|
when 'topLeftCell'
|
39
|
-
@top_left_cell = Coordinates.
|
39
|
+
@top_left_cell = Coordinates.new.parse_string(value.value)
|
40
40
|
when 'workbookViewId'
|
41
41
|
@workbook_view_id = value.value.to_i
|
42
42
|
when 'zoomScale'
|
@@ -34,7 +34,7 @@ module OoxmlParser
|
|
34
34
|
node.xpath('*').each do |node_child|
|
35
35
|
case node_child.name
|
36
36
|
when 'c'
|
37
|
-
@cells[Coordinates.
|
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)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
self
|
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.23.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-01
|
13
|
+
date: 2022-05-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
@@ -40,20 +40,6 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '1'
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: ruby-filemagic
|
45
|
-
requirement: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '0'
|
50
|
-
type: :runtime
|
51
|
-
prerelease: false
|
52
|
-
version_requirements: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - "~>"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '0'
|
57
43
|
- !ruby/object:Gem::Dependency
|
58
44
|
name: rubyzip
|
59
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -264,10 +250,8 @@ files:
|
|
264
250
|
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/non_visual_shape_properties/non_visual_properties/shape_placeholder.rb
|
265
251
|
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb
|
266
252
|
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style.rb
|
267
|
-
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/effect_reference.rb
|
268
|
-
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/fill_reference.rb
|
269
253
|
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/font_reference.rb
|
270
|
-
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/
|
254
|
+
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/style_matrix_reference.rb
|
271
255
|
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/text_body.rb
|
272
256
|
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties.rb
|
273
257
|
- lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_body_properties/ooxml_shape_body_properties/preset_text_warp.rb
|
@@ -374,6 +358,7 @@ files:
|
|
374
358
|
- lib/ooxml_parser/common_parser/common_data/valued_child.rb
|
375
359
|
- lib/ooxml_parser/common_parser/common_document_structure.rb
|
376
360
|
- lib/ooxml_parser/common_parser/parser.rb
|
361
|
+
- lib/ooxml_parser/common_parser/parser/encryption_checker.rb
|
377
362
|
- lib/ooxml_parser/configuration.rb
|
378
363
|
- lib/ooxml_parser/docx_parser/docx_data/document_structure.rb
|
379
364
|
- lib/ooxml_parser/docx_parser/docx_data/document_structure/comments.rb
|
@@ -609,14 +594,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
609
594
|
requirements:
|
610
595
|
- - ">="
|
611
596
|
- !ruby/object:Gem::Version
|
612
|
-
version: '2.
|
597
|
+
version: '2.6'
|
613
598
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
614
599
|
requirements:
|
615
600
|
- - ">="
|
616
601
|
- !ruby/object:Gem::Version
|
617
602
|
version: '0'
|
618
603
|
requirements: []
|
619
|
-
rubygems_version: 3.3.
|
604
|
+
rubygems_version: 3.3.12
|
620
605
|
signing_key:
|
621
606
|
specification_version: 4
|
622
607
|
summary: OoxmlParser Gem
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OoxmlParser
|
4
|
-
# Class for parsing `a:fillRef` tags
|
5
|
-
class FillReference < OOXMLDocumentObject
|
6
|
-
# @return [Integer] Style Matrix Index
|
7
|
-
attr_reader :index
|
8
|
-
# @return [Color] scheme color of FillReference
|
9
|
-
attr_reader :scheme_color
|
10
|
-
|
11
|
-
# Parse FillReference object
|
12
|
-
# @param node [Nokogiri::XML:Element] node to parse
|
13
|
-
# @return [FillReference] result of parsing
|
14
|
-
def parse(node)
|
15
|
-
node.attributes.each do |key, value|
|
16
|
-
case key
|
17
|
-
when 'idx'
|
18
|
-
@index = value.value.to_f
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
node.xpath('*').each do |node_child|
|
23
|
-
case node_child.name
|
24
|
-
when 'schemeClr'
|
25
|
-
@scheme_color = Color.new(parent: self).parse_scheme_color(node_child)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
self
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OoxmlParser
|
4
|
-
# Class for parsing `a:lnRef` tags
|
5
|
-
class LineReference < OOXMLDocumentObject
|
6
|
-
# @return [Integer] Style Matrix Index
|
7
|
-
attr_reader :index
|
8
|
-
# @return [Color] scheme color of LineReference
|
9
|
-
attr_reader :scheme_color
|
10
|
-
|
11
|
-
# Parse LineReference object
|
12
|
-
# @param node [Nokogiri::XML:Element] node to parse
|
13
|
-
# @return [LineReference] result of parsing
|
14
|
-
def parse(node)
|
15
|
-
node.attributes.each do |key, value|
|
16
|
-
case key
|
17
|
-
when 'idx'
|
18
|
-
@index = value.value.to_f
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
node.xpath('*').each do |node_child|
|
23
|
-
case node_child.name
|
24
|
-
when 'schemeClr'
|
25
|
-
@scheme_color = Color.new(parent: self).parse_scheme_color(node_child)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
self
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|