ooxml_parser 0.18.1 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb +14 -0
- data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +17 -2
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +15 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_spacing.rb +13 -1
- data/lib/ooxml_parser/common_parser/parser.rb +2 -1
- data/lib/ooxml_parser/version.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/sheet.rb +39 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/cell_style/protection.rb +32 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/xf.rb +5 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/workbook_protection.rb +38 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/protected_range.rb +42 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_protection.rb +117 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/selection.rb +30 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb +20 -3
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/client_data.rb +27 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb +5 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +13 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +18 -1
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f18fbe0fd1cdc17b4fa15edd44442ab0aab56a6620ba4539635b4e8c2d676b3c
|
4
|
+
data.tar.gz: de14faa95be23f0a4dc6fa9541adf184fed69bc769f837d30a2fd63321f7b765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65800c4573bb1859c02d5795c0e45b6bd50b07349aaeba24e3c1565e09022f0a25c3ddff43780cb7642b02c76343ad929e3304e4bb4a75d555158c47ff47537e
|
7
|
+
data.tar.gz: b67e977b6af0047b52d2dce951fc57335bb80758bfd0a5188a9afa30a343ac408bcd227d41d14e0481e2ff4c3ae10dda283160dcd72962994f193aa69d8f59f4
|
@@ -10,9 +10,16 @@ module OoxmlParser
|
|
10
10
|
# Class for parsing `sp`, `wsp` tags
|
11
11
|
class DocxShape < OOXMLDocumentObject
|
12
12
|
attr_accessor :non_visual_properties, :properties, :style, :body_properties, :text_body
|
13
|
+
# @return [True, False] Specifies if text in shape is locked when sheet is protected
|
14
|
+
attr_reader :locks_text
|
13
15
|
|
14
16
|
alias shape_properties properties
|
15
17
|
|
18
|
+
def initialize(parent: nil)
|
19
|
+
@locks_text = true
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
16
23
|
# @return [True, false] if structure contain any user data
|
17
24
|
def with_data?
|
18
25
|
return true if @text_body.nil?
|
@@ -27,6 +34,13 @@ module OoxmlParser
|
|
27
34
|
# @param node [Nokogiri::XML:Element] node to parse
|
28
35
|
# @return [DocxShape] result of parsing
|
29
36
|
def parse(node)
|
37
|
+
node.attributes.each do |key, value|
|
38
|
+
case key
|
39
|
+
when 'fLocksText'
|
40
|
+
@locks_text = attribute_enabled?(value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
node.xpath('*').each do |node_child|
|
31
45
|
case node_child.name
|
32
46
|
when 'nvSpPr'
|
@@ -76,14 +76,29 @@ module OoxmlParser
|
|
76
76
|
@action = :last_slide
|
77
77
|
when 'ppaction://hlinksldjump'
|
78
78
|
@action = :slide
|
79
|
-
|
79
|
+
parse_url_for_slide_link
|
80
80
|
else
|
81
|
-
if
|
81
|
+
if meaningful_id?
|
82
82
|
@action = :external_link
|
83
83
|
@url = OOXMLDocumentObject.get_link_from_rels(@id)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
self
|
87
87
|
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
# Check if id parameter has any information in it
|
92
|
+
# @return [Boolean] Can id be used
|
93
|
+
def meaningful_id?
|
94
|
+
@id && !@id.empty?
|
95
|
+
end
|
96
|
+
|
97
|
+
# Parse url for slide link
|
98
|
+
def parse_url_for_slide_link
|
99
|
+
return unless meaningful_id?
|
100
|
+
|
101
|
+
@url = OOXMLDocumentObject.get_link_from_rels(@id).scan(/\d+/).join.to_i
|
102
|
+
end
|
88
103
|
end
|
89
104
|
end
|
@@ -4,6 +4,7 @@ require 'filemagic' unless Gem.win_platform?
|
|
4
4
|
require 'securerandom'
|
5
5
|
require 'nokogiri'
|
6
6
|
require 'zip'
|
7
|
+
require 'ooxml_decrypt'
|
7
8
|
require_relative 'ooxml_document_object/nokogiri_parsing_exception'
|
8
9
|
require_relative 'ooxml_document_object/ooxml_document_object_helper'
|
9
10
|
require_relative 'ooxml_document_object/ooxml_object_attribute_helper'
|
@@ -95,6 +96,20 @@ module OoxmlParser
|
|
95
96
|
file_path
|
96
97
|
end
|
97
98
|
|
99
|
+
# Decrypt file protected with password
|
100
|
+
# @param path [String] path to file
|
101
|
+
# @param password [String] password to file
|
102
|
+
# @return [String] path to decrypted file
|
103
|
+
def decrypt_file(path, password)
|
104
|
+
file_name = File.basename(path)
|
105
|
+
tmp_folder = Dir.mktmpdir('ruby-ooxml-parser')
|
106
|
+
decrypted_path = "#{tmp_folder}/#{file_name}"
|
107
|
+
binary_password = password.encode('utf-16le').bytes.pack('c*').encode('binary')
|
108
|
+
OoxmlDecrypt::EncryptedFile.decrypt_to_file(path, binary_password, decrypted_path)
|
109
|
+
|
110
|
+
decrypted_path
|
111
|
+
end
|
112
|
+
|
98
113
|
# Unzip specified file
|
99
114
|
# @param path_to_file [String] path to zip file
|
100
115
|
# @param destination [String] folder to extract
|
data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_spacing.rb
CHANGED
@@ -16,7 +16,7 @@ module OoxmlParser
|
|
16
16
|
# @param [Nokogiri::XML:Node] node with ParagraphSpacing
|
17
17
|
# @return [ParagraphSpacing] result of parsing
|
18
18
|
def parse(node)
|
19
|
-
node.
|
19
|
+
sorted_attributes(node).each do |key, value|
|
20
20
|
case key
|
21
21
|
when 'before'
|
22
22
|
@before = OoxmlSize.new(value.value.to_f)
|
@@ -34,5 +34,17 @@ module OoxmlParser
|
|
34
34
|
end
|
35
35
|
self
|
36
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# This is dirty workaround for situations
|
41
|
+
# Then @line_rule parsed after @line so getting
|
42
|
+
# @line value is totally screwed up
|
43
|
+
# @param [Nokogiri::XML:Node] node with ParagraphSpacing
|
44
|
+
# @return [Hash] hash with sorted values
|
45
|
+
# TODO: Totally redone parsing of spacing to remove this workaround
|
46
|
+
def sorted_attributes(node)
|
47
|
+
node.attributes.sort.reverse.to_h
|
48
|
+
end
|
37
49
|
end
|
38
50
|
end
|
@@ -21,7 +21,8 @@ module OoxmlParser
|
|
21
21
|
# Base method to parse document of any type
|
22
22
|
# @param path_to_file [String] file
|
23
23
|
# @return [CommonDocumentStructure] structure of doc
|
24
|
-
def self.parse(path_to_file)
|
24
|
+
def self.parse(path_to_file, password: nil)
|
25
|
+
path_to_file = OOXMLDocumentObject.decrypt_file(path_to_file, password) if password
|
25
26
|
Parser.parse_format(path_to_file) do
|
26
27
|
format = Parser.recognize_folder_format
|
27
28
|
case format
|
data/lib/ooxml_parser/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for parsing <sheet> tag
|
5
|
+
class Sheet < OOXMLDocumentObject
|
6
|
+
# @return [String] Name of sheet
|
7
|
+
attr_reader :name
|
8
|
+
# @return [Integer] SheetId of sheet
|
9
|
+
attr_reader :sheet_id
|
10
|
+
# @return [Symbol] Specifies if sheet is hidden
|
11
|
+
attr_reader :state
|
12
|
+
# @return [String] Id of sheet
|
13
|
+
attr_reader :id
|
14
|
+
|
15
|
+
def initialize(parent: nil)
|
16
|
+
@state = :visible
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
# Parse Sheet data
|
21
|
+
# @param [Nokogiri::XML:Element] node with Sheet data
|
22
|
+
# @return [Sheet] value of Sheet
|
23
|
+
def parse(node)
|
24
|
+
node.attributes.each do |key, value|
|
25
|
+
case key
|
26
|
+
when 'name'
|
27
|
+
@name = value.value.to_s
|
28
|
+
when 'sheetId'
|
29
|
+
@sheet_id = value.value.to_i
|
30
|
+
when 'state'
|
31
|
+
@state = value.value.to_sym
|
32
|
+
when 'id'
|
33
|
+
@id = value.value.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for parsing <protection> tag
|
5
|
+
class Protection < OOXMLDocumentObject
|
6
|
+
# @return [True, False] Specifies if cell is locked
|
7
|
+
attr_reader :locked
|
8
|
+
# @return [True, False] Specifies if formulas in cell are hidden
|
9
|
+
attr_reader :hidden
|
10
|
+
|
11
|
+
def initialize(parent: nil)
|
12
|
+
@locked = true
|
13
|
+
@hidden = false
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
# Parse Protection data
|
18
|
+
# @param [Nokogiri::XML:Element] node with Protection data
|
19
|
+
# @return [Sheet] value of Protection
|
20
|
+
def parse(node)
|
21
|
+
node.attributes.each do |key, value|
|
22
|
+
case key
|
23
|
+
when 'locked'
|
24
|
+
@locked = attribute_enabled?(value)
|
25
|
+
when 'hidden'
|
26
|
+
@hidden = attribute_enabled?(value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'cell_style/alignment'
|
4
|
+
require_relative 'cell_style/protection'
|
4
5
|
module OoxmlParser
|
5
6
|
# Class for parsing `xf` object
|
6
7
|
class Xf < OOXMLDocumentObject
|
@@ -76,6 +77,8 @@ module OoxmlParser
|
|
76
77
|
attr_reader :fill_id
|
77
78
|
# @return [Integer] id of number format
|
78
79
|
attr_reader :number_format_id
|
80
|
+
# @return [Protection] Settings of cell protection
|
81
|
+
attr_reader :protection
|
79
82
|
|
80
83
|
def initialize(parent: nil)
|
81
84
|
@numerical_format = 'General'
|
@@ -115,6 +118,8 @@ module OoxmlParser
|
|
115
118
|
case node_child.name
|
116
119
|
when 'alignment'
|
117
120
|
@alignment.parse(node_child) if @apply_alignment
|
121
|
+
when 'protection'
|
122
|
+
@protection = Protection.new(parent: self).parse(node_child)
|
118
123
|
end
|
119
124
|
end
|
120
125
|
self
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for parsing <workbookProtection> tag
|
5
|
+
class WorkbookProtection < OOXMLDocumentObject
|
6
|
+
# @return [True, False] Specifies if workbook structure is protected
|
7
|
+
attr_reader :lock_structure
|
8
|
+
# @return [String] name of hashing algorithm
|
9
|
+
attr_reader :workbook_algorithm_name
|
10
|
+
# @return [String] hash value for the password
|
11
|
+
attr_reader :workbook_hash_value
|
12
|
+
# @return [String] salt value for the password
|
13
|
+
attr_reader :workbook_salt_value
|
14
|
+
# @return [Integer] number of times the hashing function shall be iteratively run
|
15
|
+
attr_reader :workbook_spin_count
|
16
|
+
|
17
|
+
# Parse WorkbookProtection data
|
18
|
+
# @param [Nokogiri::XML:Element] node with WorkbookProtection data
|
19
|
+
# @return [Sheet] value of WorkbookProtection
|
20
|
+
def parse(node)
|
21
|
+
node.attributes.each do |key, value|
|
22
|
+
case key
|
23
|
+
when 'lockStructure'
|
24
|
+
@lock_structure = attribute_enabled?(value)
|
25
|
+
when 'workbookAlgorithmName'
|
26
|
+
@workbook_algorithm_name = value.value.to_s
|
27
|
+
when 'workbookHashValue'
|
28
|
+
@workbook_hash_value = value.value.to_s
|
29
|
+
when 'workbookSaltValue'
|
30
|
+
@workbook_salt_value = value.value.to_s
|
31
|
+
when 'workbookSpinCount'
|
32
|
+
@workbook_spin_count = value.value.to_i
|
33
|
+
end
|
34
|
+
end
|
35
|
+
self
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for parsing <protectedRange> tag
|
5
|
+
class ProtectedRange < OOXMLDocumentObject
|
6
|
+
# @return [String] Name of hashing algorithm
|
7
|
+
attr_reader :algorithm_name
|
8
|
+
# @return [String] Hash value for the password
|
9
|
+
attr_reader :hash_value
|
10
|
+
# @return [String] Salt value for the password
|
11
|
+
attr_reader :salt_value
|
12
|
+
# @return [Integer] Number of times the hashing function shall be iteratively run
|
13
|
+
attr_reader :spin_count
|
14
|
+
# @return [String] Name of protected range
|
15
|
+
attr_accessor :name
|
16
|
+
# @return [String] Range reference
|
17
|
+
attr_reader :reference_sequence
|
18
|
+
|
19
|
+
# Parse ProtectedRange data
|
20
|
+
# @param [Nokogiri::XML:Element] node with ProtectedRange data
|
21
|
+
# @return [Sheet] value of ProtectedRange
|
22
|
+
def parse(node)
|
23
|
+
node.attributes.each do |key, value|
|
24
|
+
case key
|
25
|
+
when 'algorithmName'
|
26
|
+
@algorithm_name = value.value.to_s
|
27
|
+
when 'hashValue'
|
28
|
+
@hash_value = value.value.to_s
|
29
|
+
when 'saltValue'
|
30
|
+
@salt_value = value.value.to_s
|
31
|
+
when 'spinCount'
|
32
|
+
@spin_count = value.value.to_i
|
33
|
+
when 'name'
|
34
|
+
@name = value.value.to_s
|
35
|
+
when 'sqref'
|
36
|
+
@reference_sequence = value.value.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
self
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for parsing <sheetProtection> tag
|
5
|
+
class SheetProtection < OOXMLDocumentObject
|
6
|
+
# @return [String] Name of hashing algorithm
|
7
|
+
attr_reader :algorithm_name
|
8
|
+
# @return [String] Hash value for the password
|
9
|
+
attr_reader :hash_value
|
10
|
+
# @return [String] Salt value for the password
|
11
|
+
attr_reader :salt_value
|
12
|
+
# @return [Integer] Number of times the hashing function shall be iteratively run
|
13
|
+
attr_reader :spin_count
|
14
|
+
# @return [True, False] Specifies if sheet is protected
|
15
|
+
attr_reader :sheet
|
16
|
+
# @return [True, False] Specifies if using autofilter is not allowed on protected sheet
|
17
|
+
attr_reader :auto_filter
|
18
|
+
# @return [True, False] Specifies if deleting columns is not allowed on protected sheet
|
19
|
+
attr_reader :delete_columns
|
20
|
+
# @return [True, False] Specifies if deleting rows is not allowed on protected sheet
|
21
|
+
attr_reader :delete_rows
|
22
|
+
# @return [True, False] Specifies if formatting cells is not allowed on protected sheet
|
23
|
+
attr_reader :format_cells
|
24
|
+
# @return [True, False] Specifies if formatting columns is not allowed on protected sheet
|
25
|
+
attr_reader :format_columns
|
26
|
+
# @return [True, False] Specifies if formatting rows is not allowed on protected sheet
|
27
|
+
attr_reader :format_rows
|
28
|
+
# @return [True, False] Specifies if inserting columns is not allowed on protected sheet
|
29
|
+
attr_reader :insert_columns
|
30
|
+
# @return [True, False] Specifies if inserting rows is not allowed on protected sheet
|
31
|
+
attr_reader :insert_rows
|
32
|
+
# @return [True, False] Specifies if inserting hyperlinks is not allowed on protected sheet
|
33
|
+
attr_reader :insert_hyperlinks
|
34
|
+
# @return [True, False] Specifies if editing objects is not allowed on protected sheet
|
35
|
+
attr_reader :objects
|
36
|
+
# @return [True, False] Specifies if using pivot tables is not allowed on protected sheet
|
37
|
+
attr_reader :pivot_tables
|
38
|
+
# @return [True, False] Specifies if editing scenarios is not allowed on protected sheet
|
39
|
+
attr_reader :scenarios
|
40
|
+
# @return [True, False] Specifies if selecting locked cells is not allowed on protected sheet
|
41
|
+
attr_reader :select_locked_cells
|
42
|
+
# @return [True, False] Specifies if selecting unlocked cells is not allowed on protected sheet
|
43
|
+
attr_reader :select_unlocked_cells
|
44
|
+
# @return [True, False] Specifies if sorting is not allowed on protected sheet
|
45
|
+
attr_reader :sort
|
46
|
+
|
47
|
+
def initialize(parent: nil)
|
48
|
+
@objects = false
|
49
|
+
@scenarios = false
|
50
|
+
@select_locked_cells = false
|
51
|
+
@select_unlocked_cells = false
|
52
|
+
@auto_filter = true
|
53
|
+
@delete_columns = true
|
54
|
+
@delete_rows = true
|
55
|
+
@format_cells = true
|
56
|
+
@format_columns = true
|
57
|
+
@format_rows = true
|
58
|
+
@insert_columns = true
|
59
|
+
@insert_rows = true
|
60
|
+
@insert_hyperlinks = true
|
61
|
+
@pivot_tables = true
|
62
|
+
@sort = true
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
# Parse SheetProtection data
|
67
|
+
# @param [Nokogiri::XML:Element] node with SheetProtection data
|
68
|
+
# @return [Sheet] value of SheetProtection
|
69
|
+
def parse(node)
|
70
|
+
node.attributes.each do |key, value|
|
71
|
+
case key
|
72
|
+
when 'algorithmName'
|
73
|
+
@algorithm_name = value.value.to_s
|
74
|
+
when 'hashValue'
|
75
|
+
@hash_value = value.value.to_s
|
76
|
+
when 'saltValue'
|
77
|
+
@salt_value = value.value.to_s
|
78
|
+
when 'spinCount'
|
79
|
+
@spin_count = value.value.to_i
|
80
|
+
when 'sheet'
|
81
|
+
@sheet = attribute_enabled?(value)
|
82
|
+
when 'autoFilter'
|
83
|
+
@auto_filter = attribute_enabled?(value)
|
84
|
+
when 'deleteColumns'
|
85
|
+
@delete_columns = attribute_enabled?(value)
|
86
|
+
when 'deleteRows'
|
87
|
+
@delete_rows = attribute_enabled?(value)
|
88
|
+
when 'formatCells'
|
89
|
+
@format_cells = attribute_enabled?(value)
|
90
|
+
when 'formatColumns'
|
91
|
+
@format_columns = attribute_enabled?(value)
|
92
|
+
when 'formatRows'
|
93
|
+
@format_rows = attribute_enabled?(value)
|
94
|
+
when 'insertColumns'
|
95
|
+
@insert_columns = attribute_enabled?(value)
|
96
|
+
when 'insertRows'
|
97
|
+
@insert_rows = attribute_enabled?(value)
|
98
|
+
when 'insertHyperlinks'
|
99
|
+
@insert_hyperlinks = attribute_enabled?(value)
|
100
|
+
when 'objects'
|
101
|
+
@objects = attribute_enabled?(value)
|
102
|
+
when 'pivotTables'
|
103
|
+
@pivot_tables = attribute_enabled?(value)
|
104
|
+
when 'scenarios'
|
105
|
+
@scenarios = attribute_enabled?(value)
|
106
|
+
when 'selectLockedCells'
|
107
|
+
@select_locked_cells = attribute_enabled?(value)
|
108
|
+
when 'selectUnlockedCells'
|
109
|
+
@select_unlocked_cells = attribute_enabled?(value)
|
110
|
+
when 'sort'
|
111
|
+
@sort = attribute_enabled?(value)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
self
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/selection.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for `selection` data
|
5
|
+
class Selection < OOXMLDocumentObject
|
6
|
+
# @return [Coordinates] Reference to the active cell
|
7
|
+
attr_reader :active_cell
|
8
|
+
# @return [Integer] Id of active cell
|
9
|
+
attr_reader :active_cell_id
|
10
|
+
# @return [String] Selected range
|
11
|
+
attr_reader :reference_sequence
|
12
|
+
|
13
|
+
# Parse Selection object
|
14
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
15
|
+
# @return [Selection] result of parsing
|
16
|
+
def parse(node)
|
17
|
+
node.attributes.each do |key, value|
|
18
|
+
case key
|
19
|
+
when 'activeCell'
|
20
|
+
@active_cell = Coordinates.parse_coordinates_from_string(value.value)
|
21
|
+
when 'activeCellId'
|
22
|
+
@active_cell_id = value.value.to_i
|
23
|
+
when 'sqref'
|
24
|
+
@reference_sequence = value.value.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'sheet_view/pane'
|
4
|
+
require_relative 'sheet_view/selection'
|
4
5
|
module OoxmlParser
|
5
6
|
# Class for `sheetView` data
|
6
7
|
class SheetView < OOXMLDocumentObject
|
@@ -9,6 +10,14 @@ module OoxmlParser
|
|
9
10
|
attr_accessor :show_gridlines
|
10
11
|
# @return [True, False] Flag indicating whether the sheet should display row and column headings.
|
11
12
|
attr_accessor :show_row_column_headers
|
13
|
+
# @return [Coordinates] Reference to the top left cell
|
14
|
+
attr_reader :top_left_cell
|
15
|
+
# @return [Integer] Id of workbook view
|
16
|
+
attr_reader :workbook_view_id
|
17
|
+
# @return [Integer] Zoom scale
|
18
|
+
attr_reader :zoom_scale
|
19
|
+
# @return [Selection] Properties of selection
|
20
|
+
attr_reader :selection
|
12
21
|
|
13
22
|
def initialize(parent: nil)
|
14
23
|
@show_gridlines = true
|
@@ -20,12 +29,18 @@ module OoxmlParser
|
|
20
29
|
# @param node [Nokogiri::XML:Element] node to parse
|
21
30
|
# @return [SheetView] result of parsing
|
22
31
|
def parse(node)
|
23
|
-
node.attributes.
|
32
|
+
node.attributes.each do |key, value|
|
24
33
|
case key
|
25
34
|
when 'showGridLines'
|
26
|
-
@show_gridlines = attribute_enabled?(
|
35
|
+
@show_gridlines = attribute_enabled?(value)
|
27
36
|
when 'showRowColHeaders'
|
28
|
-
@show_row_column_headers = attribute_enabled?(
|
37
|
+
@show_row_column_headers = attribute_enabled?(value)
|
38
|
+
when 'topLeftCell'
|
39
|
+
@top_left_cell = Coordinates.parse_coordinates_from_string(value.value)
|
40
|
+
when 'workbookViewId'
|
41
|
+
@workbook_view_id = value.value.to_i
|
42
|
+
when 'zoomScale'
|
43
|
+
@zoom_scale = value.value.to_i
|
29
44
|
end
|
30
45
|
end
|
31
46
|
|
@@ -33,6 +48,8 @@ module OoxmlParser
|
|
33
48
|
case node_child.name
|
34
49
|
when 'pane'
|
35
50
|
@pane = Pane.new(parent: self).parse(node_child)
|
51
|
+
when 'selection'
|
52
|
+
@selection = Selection.new(parent: self).parse(node_child)
|
36
53
|
end
|
37
54
|
end
|
38
55
|
self
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OoxmlParser
|
4
|
+
# Class for parsing <clientData> tag
|
5
|
+
class ClientData < OOXMLDocumentObject
|
6
|
+
# @return [True, False] Specifies if drawing is locked when sheet is protected
|
7
|
+
attr_reader :locks_with_sheet
|
8
|
+
|
9
|
+
def initialize(parent: nil)
|
10
|
+
@locks_with_sheet = true
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
# Parse ClientData data
|
15
|
+
# @param [Nokogiri::XML:Element] node with ClientData data
|
16
|
+
# @return [Sheet] value of ClientData
|
17
|
+
def parse(node)
|
18
|
+
node.attributes.each do |key, value|
|
19
|
+
case key
|
20
|
+
when 'fLocksWithSheet'
|
21
|
+
@locks_with_sheet = attribute_enabled?(value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'xlsx_drawing/xlsx_drawing_position_parameters'
|
4
|
+
require_relative 'xlsx_drawing/client_data'
|
4
5
|
module OoxmlParser
|
5
6
|
# Data of spreadsheet drawing
|
6
7
|
class XlsxDrawing < OOXMLDocumentObject
|
@@ -11,6 +12,8 @@ module OoxmlParser
|
|
11
12
|
attr_accessor :to
|
12
13
|
# @return [GraphicFrame] graphic frame
|
13
14
|
attr_accessor :graphic_frame
|
15
|
+
# @return [ClientData] client data
|
16
|
+
attr_accessor :client_data
|
14
17
|
|
15
18
|
# Parse XlsxDrawing object
|
16
19
|
# @param node [Nokogiri::XML:Element] node to parse
|
@@ -32,6 +35,8 @@ module OoxmlParser
|
|
32
35
|
@graphic_frame = GraphicFrame.new(parent: self).parse(child_node)
|
33
36
|
when 'cxnSp'
|
34
37
|
@shape = ConnectionShape.new(parent: self).parse(child_node)
|
38
|
+
when 'clientData'
|
39
|
+
@client_data = ClientData.new(parent: self).parse(child_node)
|
35
40
|
end
|
36
41
|
end
|
37
42
|
self
|
@@ -11,6 +11,8 @@ require_relative 'worksheet/xlsx_column_properties'
|
|
11
11
|
require_relative 'worksheet/xlsx_drawing'
|
12
12
|
require_relative 'worksheet/xlsx_row'
|
13
13
|
require_relative 'worksheet/xlsx_header_footer'
|
14
|
+
require_relative 'worksheet/sheet_protection'
|
15
|
+
require_relative 'worksheet/protected_range'
|
14
16
|
module OoxmlParser
|
15
17
|
# Properties of worksheet
|
16
18
|
class Worksheet < OOXMLDocumentObject
|
@@ -33,6 +35,10 @@ module OoxmlParser
|
|
33
35
|
attr_reader :header_footer
|
34
36
|
# @return [Array<ConditionalFormatting>] list of conditional formattings
|
35
37
|
attr_reader :conditional_formattings
|
38
|
+
# @return [SheetProtection] protection of sheet
|
39
|
+
attr_reader :sheet_protection
|
40
|
+
# @return [Array<ProtectedRange>] list of protected ranges
|
41
|
+
attr_reader :protected_ranges
|
36
42
|
|
37
43
|
def initialize(parent: nil)
|
38
44
|
@columns = []
|
@@ -45,6 +51,7 @@ module OoxmlParser
|
|
45
51
|
@sheet_views = []
|
46
52
|
@table_parts = []
|
47
53
|
@conditional_formattings = []
|
54
|
+
@protected_ranges = []
|
48
55
|
super
|
49
56
|
end
|
50
57
|
|
@@ -134,6 +141,12 @@ module OoxmlParser
|
|
134
141
|
@header_footer = XlsxHeaderFooter.new(parent: self).parse(worksheet_node_child)
|
135
142
|
when 'conditionalFormatting'
|
136
143
|
@conditional_formattings << ConditionalFormatting.new(parent: self).parse(worksheet_node_child)
|
144
|
+
when 'sheetProtection'
|
145
|
+
@sheet_protection = SheetProtection.new(parent: self).parse(worksheet_node_child)
|
146
|
+
when 'protectedRanges'
|
147
|
+
worksheet_node_child.xpath('*').each do |protected_range_node|
|
148
|
+
@protected_ranges << ProtectedRange.new(parent: self).parse(protected_range_node)
|
149
|
+
end
|
137
150
|
end
|
138
151
|
end
|
139
152
|
parse_comments
|
@@ -4,15 +4,19 @@ require_relative 'workbook/chartsheet'
|
|
4
4
|
require_relative 'workbook/pivot_cache'
|
5
5
|
require_relative 'workbook/pivot_table_definition'
|
6
6
|
require_relative 'workbook/defined_name'
|
7
|
+
require_relative 'workbook/workbook_protection'
|
7
8
|
require_relative 'workbook/shared_string_table'
|
8
9
|
require_relative 'workbook/style_sheet'
|
9
10
|
require_relative 'workbook/worksheet'
|
11
|
+
require_relative 'workbook/sheet'
|
10
12
|
require_relative 'workbook/workbook_helpers'
|
11
13
|
module OoxmlParser
|
12
14
|
# Class for storing XLSX Workbook
|
13
15
|
class XLSXWorkbook < CommonDocumentStructure
|
14
16
|
include WorkbookHelpers
|
15
17
|
attr_accessor :worksheets
|
18
|
+
# @return [Array<Sheet>] list of sheets
|
19
|
+
attr_reader :sheets
|
16
20
|
# @return [PresentationTheme] theme of Workbook
|
17
21
|
attr_accessor :theme
|
18
22
|
# @return [Relationships] rels of book
|
@@ -27,9 +31,12 @@ module OoxmlParser
|
|
27
31
|
attr_accessor :pivot_table_definitions
|
28
32
|
# @return [Array<DefinedName>] list of defined names
|
29
33
|
attr_reader :defined_names
|
34
|
+
# @return [WorkbookProtection] protection of workbook structure
|
35
|
+
attr_reader :workbook_protection
|
30
36
|
|
31
37
|
def initialize(params = {})
|
32
38
|
@worksheets = []
|
39
|
+
@sheets = []
|
33
40
|
@pivot_caches = []
|
34
41
|
@pivot_table_definitions = []
|
35
42
|
@defined_names = []
|
@@ -119,10 +126,11 @@ module OoxmlParser
|
|
119
126
|
@theme = PresentationTheme.parse("xl/#{link_to_theme_xml}") if link_to_theme_xml
|
120
127
|
@style_sheet = StyleSheet.new(parent: self).parse
|
121
128
|
@doc.xpath('xmlns:workbook/xmlns:sheets/xmlns:sheet').each do |sheet|
|
129
|
+
@sheets << Sheet.new(parent: self).parse(sheet)
|
122
130
|
file = @relationships.target_by_id(sheet.attribute('id').value)
|
123
131
|
if file.start_with?('worksheets')
|
124
132
|
@worksheets << Worksheet.new(parent: self).parse(file)
|
125
|
-
@worksheets.last.name =
|
133
|
+
@worksheets.last.name = @sheets.last.name
|
126
134
|
elsif file.start_with?('chartsheets')
|
127
135
|
@worksheets << Chartsheet.new(parent: self).parse(file)
|
128
136
|
end
|
@@ -130,6 +138,7 @@ module OoxmlParser
|
|
130
138
|
parse_pivot_cache
|
131
139
|
parse_pivot_table
|
132
140
|
parse_defined_names
|
141
|
+
parse_workbook_protection
|
133
142
|
OOXMLDocumentObject.xmls_stack.pop
|
134
143
|
self
|
135
144
|
end
|
@@ -161,5 +170,13 @@ module OoxmlParser
|
|
161
170
|
@defined_names << DefinedName.new(parent: self).parse(defined_name)
|
162
171
|
end
|
163
172
|
end
|
173
|
+
|
174
|
+
# Perform parsing of workbook protection
|
175
|
+
def parse_workbook_protection
|
176
|
+
workbook_protection = @doc.search('//xmlns:workbookProtection').first
|
177
|
+
return nil unless workbook_protection
|
178
|
+
|
179
|
+
@workbook_protection = WorkbookProtection.new(parent: self).parse(workbook_protection)
|
180
|
+
end
|
164
181
|
end
|
165
182
|
end
|
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.22.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:
|
13
|
+
date: 2022-01-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: ooxml_decrypt
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1'
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: ruby-filemagic
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -510,9 +524,11 @@ files:
|
|
510
524
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_table_definition/pivot_table_style_info.rb
|
511
525
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/shared_string_table.rb
|
512
526
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/shared_string_table/string_index.rb
|
527
|
+
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/sheet.rb
|
513
528
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet.rb
|
514
529
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs.rb
|
515
530
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/cell_style/alignment.rb
|
531
|
+
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/cell_style/protection.rb
|
516
532
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs/xf.rb
|
517
533
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/differential_formatting_records.rb
|
518
534
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills.rb
|
@@ -525,6 +541,7 @@ files:
|
|
525
541
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/xlsx_borders.rb
|
526
542
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/xlsx_borders/xlsx_border.rb
|
527
543
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/workbook_helpers.rb
|
544
|
+
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/workbook_protection.rb
|
528
545
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb
|
529
546
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb
|
530
547
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments/author.rb
|
@@ -532,9 +549,12 @@ files:
|
|
532
549
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments/excel_comment.rb
|
533
550
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/ole_objects.rb
|
534
551
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/page_setup.rb
|
552
|
+
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/protected_range.rb
|
535
553
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_format_properties.rb
|
554
|
+
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_protection.rb
|
536
555
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb
|
537
556
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/pane.rb
|
557
|
+
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view/selection.rb
|
538
558
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part.rb
|
539
559
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter.rb
|
540
560
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part/autofilter/filter_column.rb
|
@@ -563,6 +583,7 @@ files:
|
|
563
583
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/worksheet_helper.rb
|
564
584
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
|
565
585
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb
|
586
|
+
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/client_data.rb
|
566
587
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position_parameters.rb
|
567
588
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer.rb
|
568
589
|
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
|
@@ -579,6 +600,7 @@ metadata:
|
|
579
600
|
documentation_uri: https://www.rubydoc.info/gems/ooxml_parser
|
580
601
|
homepage_uri: https://github.com/onlyoffice/ooxml_parser
|
581
602
|
source_code_uri: https://github.com/onlyoffice/ooxml_parser
|
603
|
+
rubygems_mfa_required: 'true'
|
582
604
|
post_install_message:
|
583
605
|
rdoc_options: []
|
584
606
|
require_paths:
|
@@ -594,7 +616,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
594
616
|
- !ruby/object:Gem::Version
|
595
617
|
version: '0'
|
596
618
|
requirements: []
|
597
|
-
rubygems_version: 3.
|
619
|
+
rubygems_version: 3.3.4
|
598
620
|
signing_key:
|
599
621
|
specification_version: 4
|
600
622
|
summary: OoxmlParser Gem
|