ooxml_parser 0.13.0 → 0.14.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: e8d43b880b2291d11e75cf1107c546077d36d4123044cf71d0b85a5f7a62487b
4
- data.tar.gz: 6690b7dad0c09b17ac772af66a6f614a8e68331c6ddb247597cf818887e4b16e
3
+ metadata.gz: bbe984c75d77c22d3cc76c2773670e672669c8f66f57a62bddb8a4acdf7d55dd
4
+ data.tar.gz: 87a2b69d34c81ab84f8e9364edb72e72222fd5ac804042ff103a9fb3f17213d5
5
5
  SHA512:
6
- metadata.gz: c6c51d4331048c7250d9724da8c00354d235df4dbe8fad57cc81783133a4d0a030ce02056000afb4a5f5d13a91e4f8f28ce51d82f4d581b55da6902fe2927f1a
7
- data.tar.gz: abc21e3b8151d29985cdb96a05e60eef69feb949fc6b12f24c225ba050d08ad021de39745250dbdef4920965dcca430473d0b3f089c4ca122ea790a612026ecc
6
+ metadata.gz: bdad6fb4ea5c65cf4537d1d36b9b0c07cae3fad72d4b816a3159dc25388745cc881df13f8ff2786d0a24a543d154db82c0dc28c4697d97767170940db29cf112
7
+ data.tar.gz: faf91b9c3d03b259532661ee905ea1889061b015574dfe0f5dce513ced4da4eb68b9cbc68635809c619f4649da10696df56161218d3e8f966fc643040c46a268
@@ -23,8 +23,8 @@ module OoxmlParser
23
23
  # @return [String] text representation
24
24
  def to_s
25
25
  "Value: `#{value}`, "\
26
- "Color: `#{color}`, "\
27
- "Fill: `#{fill}`"
26
+ "Color: `#{color}`, "\
27
+ "Fill: `#{fill}`"
28
28
  end
29
29
 
30
30
  # Parse Shade
@@ -9,11 +9,11 @@ module OoxmlParser
9
9
  # @return [String] result of convert of object to string
10
10
  def to_s
11
11
  "Table position left: #{left}, "\
12
- "right: #{right}, "\
13
- "top: #{top}, "\
14
- "bottom #{bottom}, "\
15
- "position x: #{position_x}, "\
16
- "position y: #{position_y}"
12
+ "right: #{right}, "\
13
+ "top: #{top}, "\
14
+ "bottom #{bottom}, "\
15
+ "position x: #{position_x}, "\
16
+ "position y: #{position_y}"
17
17
  end
18
18
 
19
19
  # Parse TablePosition object
@@ -26,7 +26,7 @@ module OoxmlParser
26
26
  # @return [String] result of conversion
27
27
  def to_s
28
28
  "first line indent: #{@first_line_indent}, left indent: #{@left_indent}, "\
29
- "right indent: #{@right_indent}, hanging indent: #{@hanging_indent}"
29
+ "right indent: #{@right_indent}, hanging indent: #{@hanging_indent}"
30
30
  end
31
31
 
32
32
  # Parse Indents
@@ -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.13.0'
7
+ STRING = '0.14.0'
8
8
  end
9
9
  end
@@ -3,6 +3,7 @@
3
3
  require_relative 'workbook/chartsheet'
4
4
  require_relative 'workbook/pivot_cache'
5
5
  require_relative 'workbook/pivot_table_definition'
6
+ require_relative 'workbook/defined_name'
6
7
  require_relative 'workbook/shared_string_table'
7
8
  require_relative 'workbook/style_sheet'
8
9
  require_relative 'workbook/worksheet'
@@ -24,11 +25,14 @@ module OoxmlParser
24
25
  attr_accessor :pivot_caches
25
26
  # @return [Array<PivotTableDefintion>] list of pivot table defitions
26
27
  attr_accessor :pivot_table_definitions
28
+ # @return [Array<DefinedName>] list of defined names
29
+ attr_reader :defined_names
27
30
 
28
31
  def initialize(params = {})
29
32
  @worksheets = []
30
33
  @pivot_caches = []
31
34
  @pivot_table_definitions = []
35
+ @defined_names = []
32
36
  super
33
37
  end
34
38
 
@@ -125,6 +129,7 @@ module OoxmlParser
125
129
  end
126
130
  parse_pivot_cache
127
131
  parse_pivot_table
132
+ parse_defined_names
128
133
  OOXMLDocumentObject.xmls_stack.pop
129
134
  self
130
135
  end
@@ -149,5 +154,12 @@ module OoxmlParser
149
154
  @pivot_table_definitions << PivotTableDefinition.new(parent: self).parse(file.part_name)
150
155
  end
151
156
  end
157
+
158
+ # Perform parsing of defined names
159
+ def parse_defined_names
160
+ @doc.xpath('xmlns:workbook/xmlns:definedNames/xmlns:definedName').each do |defined_name|
161
+ @defined_names << DefinedName.new(parent: self).parse(defined_name)
162
+ end
163
+ end
152
164
  end
153
165
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for parsing <definedName> tag
5
+ class DefinedName < OOXMLDocumentObject
6
+ # @return [String] Ranges to which defined name refers
7
+ attr_reader :range
8
+ # @return [String] Name
9
+ attr_reader :name
10
+ # @return [String] Id of sheet
11
+ attr_reader :local_sheet_id
12
+ # @return [Symbol] Specifies whether defined name is hidden
13
+ attr_reader :hidden
14
+
15
+ # Parse Defined Name data
16
+ # @param [Nokogiri::XML:Element] node with DefinedName data
17
+ # @return [DefinedName] value of DefinedName
18
+ def parse(node)
19
+ @range = node.text
20
+ node.attributes.each do |key, value|
21
+ case key
22
+ when 'name'
23
+ @name = value.value.to_s
24
+ when 'localSheetId'
25
+ @local_sheet_id = value.value.to_i
26
+ when 'hidden'
27
+ @hidden = attribute_enabled?(value)
28
+ end
29
+ end
30
+ self
31
+ end
32
+ end
33
+ end
@@ -10,6 +10,7 @@ require_relative 'worksheet/worksheet_helper'
10
10
  require_relative 'worksheet/xlsx_column_properties'
11
11
  require_relative 'worksheet/xlsx_drawing'
12
12
  require_relative 'worksheet/xlsx_row'
13
+ require_relative 'worksheet/xlsx_header_footer'
13
14
  module OoxmlParser
14
15
  # Properties of worksheet
15
16
  class Worksheet < OOXMLDocumentObject
@@ -28,6 +29,8 @@ module OoxmlParser
28
29
  attr_reader :page_setup
29
30
  # @return [ExtensionList] list of extensions
30
31
  attr_accessor :extension_list
32
+ # @return [XlsxHeaderFooter] header and footer
33
+ attr_reader :header_footer
31
34
 
32
35
  def initialize(parent: nil)
33
36
  @columns = []
@@ -124,6 +127,8 @@ module OoxmlParser
124
127
  @page_setup = PageSetup.new(parent: self).parse(worksheet_node_child)
125
128
  when 'extLst'
126
129
  @extension_list = ExtensionList.new(parent: self).parse(worksheet_node_child)
130
+ when 'headerFooter'
131
+ @header_footer = XlsxHeaderFooter.new(parent: self).parse(worksheet_node_child)
127
132
  end
128
133
  end
129
134
  parse_comments
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'xlsx_header_footer/header_footer_child'
4
+ module OoxmlParser
5
+ # Class for parsing <headerFooter> tag
6
+ class XlsxHeaderFooter < OOXMLDocumentObject
7
+ # @return [Symbol] Specifies whether to align header with margins
8
+ attr_reader :align_with_margins
9
+ # @return [Symbol] Specifies whether first header is different
10
+ attr_reader :different_first
11
+ # @return [Symbol] Specifies whether odd and even headers are different
12
+ attr_reader :different_odd_even
13
+ # @return [Symbol] Specifies whether to scale header with document
14
+ attr_reader :scale_with_document
15
+ # @return [String] odd header
16
+ attr_reader :odd_header
17
+ # @return [String] odd footer
18
+ attr_reader :odd_footer
19
+ # @return [String] even header
20
+ attr_reader :even_header
21
+ # @return [String] even footer
22
+ attr_reader :even_footer
23
+ # @return [String] first header
24
+ attr_reader :first_header
25
+ # @return [String] first footer
26
+ attr_reader :first_footer
27
+
28
+ # Parse Header Footer data
29
+ # @param node [Nokogiri::XML:Element] node to parse
30
+ # @return [XlsxHeaderFooter] result of parsing
31
+ def parse(node)
32
+ node.attributes.each do |key, value|
33
+ case key
34
+ when 'alignWithMargins'
35
+ @align_with_margins = attribute_enabled?(value)
36
+ when 'differentFirst'
37
+ @different_first = attribute_enabled?(value)
38
+ when 'differentOddEven'
39
+ @different_odd_even = attribute_enabled?(value)
40
+ when 'scaleWithDoc'
41
+ @scale_with_document = attribute_enabled?(value)
42
+ end
43
+
44
+ node.xpath('*').each do |node_child|
45
+ case node_child.name
46
+ when 'oddHeader'
47
+ @odd_header = HeaderFooterChild.new(parent: parent, type: odd_header).parse(node_child)
48
+ when 'oddFooter'
49
+ @odd_footer = HeaderFooterChild.new(parent: parent, type: odd_footer).parse(node_child)
50
+ when 'evenHeader'
51
+ @even_header = HeaderFooterChild.new(parent: parent, type: even_header).parse(node_child)
52
+ when 'evenFooter'
53
+ @even_footer = HeaderFooterChild.new(parent: parent, type: even_footer).parse(node_child)
54
+ when 'firstHeader'
55
+ @first_header = HeaderFooterChild.new(parent: parent, type: first_header).parse(node_child)
56
+ when 'firstFooter'
57
+ @first_footer = HeaderFooterChild.new(parent: parent, type: first_footer).parse(node_child)
58
+ end
59
+ end
60
+ end
61
+ self
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OoxmlParser
4
+ # Class for parsing header or footer
5
+ class HeaderFooterChild < OOXMLDocumentObject
6
+ # @return [Symbol] type of header
7
+ attr_reader :type
8
+ # @return [String] raw text of header
9
+ attr_reader :raw_string
10
+
11
+ def initialize(type: nil, raw_string: nil, parent: nil)
12
+ @type = type
13
+ @raw_string = raw_string
14
+ super(parent: parent)
15
+ end
16
+
17
+ # Parse HeaderFooterChild data
18
+ # @param node [Nokogiri::XML:Element] node to parse
19
+ # @return [HeaderFooterChild] result of parsing
20
+ def parse(node)
21
+ @raw_string = node.text
22
+ self
23
+ end
24
+
25
+ # @return [String] right part of header
26
+ def right
27
+ return @right if @right
28
+
29
+ right = @raw_string.match(/&R(.+)/)
30
+ return nil unless right
31
+
32
+ @right = right[1]
33
+ end
34
+
35
+ # @return [String] center part of header
36
+ def center
37
+ return @center if @center
38
+
39
+ center = @raw_string.split('&R').first.match(/&C(.+)/)
40
+ return nil unless center
41
+
42
+ @center = center[1]
43
+ end
44
+
45
+ # @return [String] left part of header
46
+ def left
47
+ return @left if @left
48
+
49
+ left = @raw_string.gsub("&R#{right}", '')
50
+ left = left.gsub("&C#{center}", '')
51
+ return nil if left == ''
52
+
53
+ left.gsub('&L', '')
54
+ end
55
+ end
56
+ 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.13.0
4
+ version: 0.14.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: 2021-05-25 00:00:00.000000000 Z
13
+ date: 2021-07-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -486,6 +486,7 @@ files:
486
486
  - lib/ooxml_parser/version.rb
487
487
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb
488
488
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/chartsheet.rb
489
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/defined_name.rb
489
490
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache.rb
490
491
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition.rb
491
492
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_fields.rb
@@ -548,6 +549,8 @@ files:
548
549
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
549
550
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing.rb
550
551
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position_parameters.rb
552
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer.rb
553
+ - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_header_footer/header_footer_child.rb
551
554
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb
552
555
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb
553
556
  - lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/formula.rb
@@ -576,7 +579,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
576
579
  - !ruby/object:Gem::Version
577
580
  version: '0'
578
581
  requirements: []
579
- rubygems_version: 3.1.6
582
+ rubygems_version: 3.2.21
580
583
  signing_key:
581
584
  specification_version: 4
582
585
  summary: OoxmlParser Gem