ooxml_parser 0.5.1 → 0.8.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.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice/math_text.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/alternate_content/choice/math_text/math_paragraph.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +6 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series.rb +2 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart/series/series_text.rb +0 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/docx_drawing.rb +1 -20
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_distance_from_text.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_properties.rb +51 -4
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_coordinates.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/ooxml_size.rb +4 -1
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_picture.rb +0 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style.rb +42 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/effect_reference.rb +35 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/fill_reference.rb +35 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/font_reference.rb +35 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/shape_style/line_reference.rb +35 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/color/docx_color_scheme.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_path/docx_shape_line_element.rb +0 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb +12 -4
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb +10 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape_properties.rb +1 -3
- data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/color.rb +48 -82
- data/lib/ooxml_parser/common_parser/common_data/color/color_helper.rb +4 -3
- data/lib/ooxml_parser/common_parser/common_data/color/color_indexes.list +66 -0
- data/lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb +5 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb +8 -2
- data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +11 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/scheme_color.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/theme_colors.rb +4 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_default.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/content_types/content_type_override.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/coordinates.rb +7 -0
- data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +14 -3
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +28 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +28 -12
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/outline.rb +4 -2
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/numbering_properties.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/paragraph_borders.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb +16 -13
- data/lib/ooxml_parser/common_parser/common_data/table.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb +7 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_position.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_properties/table_style_properties_helper.rb +4 -4
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +4 -5
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/borders.rb +6 -0
- data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +3 -0
- data/lib/ooxml_parser/common_parser/common_data/underline.rb +7 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +41 -9
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/comments/comment.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph.rb +25 -8
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/bookmark_end.rb +1 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/comment_range_start.rb +1 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/pre_sub_superscript.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +13 -3
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/docx_paragraph_run_helpers.rb +4 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +0 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/indents.rb +4 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/header_footer.rb +8 -4
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering.rb +5 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/columns.rb +3 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/note.rb +6 -2
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_size.rb +1 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/styles.rb +2 -0
- data/lib/ooxml_parser/docx_parser/docx_parser.rb +3 -0
- data/lib/ooxml_parser/name.rb +1 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +2 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme/theme_color.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +5 -2
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide_helper.rb +15 -1
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +3 -0
- data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +4 -1
- data/lib/ooxml_parser/version.rb +2 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +21 -2
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/chartsheet.rb +3 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache.rb +41 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition.rb +37 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source.rb +33 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/pivot_cache/pivot_cache_definition/cache_source/worksheet_source.rb +26 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet.rb +2 -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/style_sheet/fills/fill.rb +2 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb +3 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +5 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb +4 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb +4 -0
- data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +3 -0
- metadata +70 -4
@@ -12,6 +12,9 @@ module OoxmlParser
|
|
12
12
|
# @return [DocxFormula] base
|
13
13
|
attr_accessor :base
|
14
14
|
|
15
|
+
# Parse PreSubSuperscript
|
16
|
+
# @param [Nokogiri::XML:Node] node with PreSubSuperscript
|
17
|
+
# @return [PreSubSuperscript] result of parsing
|
15
18
|
def parse(node)
|
16
19
|
node.xpath('*').each do |node_child|
|
17
20
|
case node_child.name
|
data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb
CHANGED
@@ -41,12 +41,16 @@ module OoxmlParser
|
|
41
41
|
@parent = parent
|
42
42
|
end
|
43
43
|
|
44
|
+
# Constructor for copy of object
|
45
|
+
# @param source [DocxParagraphRun] original object
|
46
|
+
# @return [void]
|
44
47
|
def initialize_copy(source)
|
45
48
|
super
|
46
49
|
@drawings = source.drawings.clone
|
47
50
|
@comments = source.comments.clone
|
48
51
|
end
|
49
52
|
|
53
|
+
# @return [Array, nil] Drawings of Run
|
50
54
|
def drawing
|
51
55
|
# TODO: Rewrite all tests without this methos
|
52
56
|
@drawings.empty? ? nil : drawings.first
|
@@ -64,6 +68,9 @@ module OoxmlParser
|
|
64
68
|
!@break
|
65
69
|
end
|
66
70
|
|
71
|
+
# Compare this object to other
|
72
|
+
# @param other [Object] any other object
|
73
|
+
# @return [True, False] result of comparision
|
67
74
|
def ==(other)
|
68
75
|
ignored_attributes = %i[@number @parent]
|
69
76
|
all_instance_variables = instance_variables
|
@@ -74,12 +81,17 @@ module OoxmlParser
|
|
74
81
|
true
|
75
82
|
end
|
76
83
|
|
84
|
+
# Parse object
|
85
|
+
# @param r_tag [Nokogiri::XML:Node] node with DocxParagraphRun
|
86
|
+
# @param char_number [Integer] number of run
|
87
|
+
# @param parent [OOXMLDocumentObject] parent of run
|
88
|
+
# @return [void]
|
77
89
|
def parse(r_tag, char_number, parent: nil)
|
78
90
|
@parent = parent
|
79
91
|
r_tag.xpath('*').each do |node_child|
|
80
92
|
case node_child.name
|
81
93
|
when 'rPr'
|
82
|
-
parse_properties(node_child
|
94
|
+
parse_properties(node_child)
|
83
95
|
@run_properties = RunProperties.new(parent: self).parse(node_child)
|
84
96
|
when 'instrText'
|
85
97
|
if node_child.text.include?('HYPERLINK')
|
@@ -121,8 +133,6 @@ module OoxmlParser
|
|
121
133
|
@shape = Shape.new(parent: self).parse(pict_node_child, :shape)
|
122
134
|
when 'rect'
|
123
135
|
@shape = Shape.new(parent: self).parse(pict_node_child, :rectangle)
|
124
|
-
when 'oval'
|
125
|
-
@shape = Shape.new(parent: self).parse(pict_node_child, :oval)
|
126
136
|
end
|
127
137
|
end
|
128
138
|
when 'object'
|
@@ -3,7 +3,10 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Module for some helpers for ParagraphRun
|
5
5
|
module DocxParagraphRunHelpers
|
6
|
-
|
6
|
+
# Parse other properties
|
7
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
8
|
+
# @return [DocxParagraphRun] result of parse
|
9
|
+
def parse_properties(node)
|
7
10
|
self.font_style = FontStyle.new
|
8
11
|
node.xpath('*').each do |node_child|
|
9
12
|
case node_child.name
|
@@ -53,8 +53,6 @@ module OoxmlParser
|
|
53
53
|
@properties.margins.top = property.split(':').last
|
54
54
|
elsif property.include?('margin-left')
|
55
55
|
@properties.margins.left = property.split(':').last
|
56
|
-
elsif property.include?('margin-right')
|
57
|
-
@properties.margins.right = property.split(':').last
|
58
56
|
elsif property.include?('width')
|
59
57
|
@properties.size.width = property.split(':').last
|
60
58
|
elsif property.include?('height')
|
data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb
CHANGED
@@ -7,6 +7,9 @@ module OoxmlParser
|
|
7
7
|
:horizontal_align, :vertical_align, :anchor_lock, :vertical_space, :horizontal_space,
|
8
8
|
:horizontal_position, :vertical_position
|
9
9
|
|
10
|
+
# Parse FrameProperties
|
11
|
+
# @param node [Nokogiri::XML:Element] with FrameProperties
|
12
|
+
# @return [FrameProperties] parsed result
|
10
13
|
def parse(node)
|
11
14
|
node.attributes.each do |key, value|
|
12
15
|
case key
|
@@ -22,9 +22,11 @@ module OoxmlParser
|
|
22
22
|
alias right right_indent
|
23
23
|
alias hanging hanging_indent
|
24
24
|
|
25
|
+
# Convert to string
|
26
|
+
# @return [String] result of conversion
|
25
27
|
def to_s
|
26
|
-
"first line indent: #{@first_line_indent}, left indent: #{@left_indent},
|
27
|
-
|
28
|
+
"first line indent: #{@first_line_indent}, left indent: #{@left_indent}, "\
|
29
|
+
"right indent: #{@right_indent}, hanging indent: #{@hanging_indent}"
|
28
30
|
end
|
29
31
|
|
30
32
|
# Parse Indents
|
@@ -3,8 +3,14 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Class Header Footer classes
|
5
5
|
class HeaderFooter < OOXMLDocumentObject
|
6
|
-
|
7
|
-
|
6
|
+
# @return [Integer] id of header-footer
|
7
|
+
attr_reader :id
|
8
|
+
# @return [Array<OOXMLDocumentObject>] list of elements if object
|
9
|
+
attr_reader :elements
|
10
|
+
# @return [Symbol] `:header` or `:footer`
|
11
|
+
attr_reader :type
|
12
|
+
# @return [String] suffix for object files
|
13
|
+
attr_reader :path_suffix
|
8
14
|
|
9
15
|
def initialize(type = :header, parent: nil)
|
10
16
|
@type = type
|
@@ -32,8 +38,6 @@ module OoxmlParser
|
|
32
38
|
when 'endnoteReference'
|
33
39
|
@path_suffix = 'endnote'
|
34
40
|
@type = :footer
|
35
|
-
else
|
36
|
-
warn "Unknown HeaderFooter type: #{node.name}"
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
@@ -17,6 +17,9 @@ module OoxmlParser
|
|
17
17
|
@parent = parent
|
18
18
|
end
|
19
19
|
|
20
|
+
# Get properties by number id
|
21
|
+
# @param num_id [Integer] index of number id
|
22
|
+
# @return [nil, AbstractNumbering] result of search
|
20
23
|
def properties_by_num_id(num_id)
|
21
24
|
abstract_num_id = nil
|
22
25
|
@numbering_definition_list.each do |num_def|
|
@@ -32,6 +35,8 @@ module OoxmlParser
|
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
38
|
+
# Parse Numbering data
|
39
|
+
# @return [Numbering] result of parse
|
35
40
|
def parse
|
36
41
|
numbering_xml = OOXMLDocumentObject.path_to_folder + 'word/numbering.xml'
|
37
42
|
return nil unless File.exist?(numbering_xml)
|
@@ -4,9 +4,12 @@ require_relative 'columns/column'
|
|
4
4
|
module OoxmlParser
|
5
5
|
# Class for data of Columns
|
6
6
|
class Columns < OOXMLDocumentObject
|
7
|
+
# @return [Integer] count of columns
|
7
8
|
attr_accessor :count
|
9
|
+
# @return [True, False] is columns are equal width
|
8
10
|
attr_accessor :equal_width
|
9
11
|
alias equal_width? equal_width
|
12
|
+
# @return [Array<Column>] list of colujmns
|
10
13
|
attr_accessor :column_array
|
11
14
|
# @return [Boolean] Draw Line Between Columns
|
12
15
|
attr_reader :separator
|
@@ -9,6 +9,9 @@ module OoxmlParser
|
|
9
9
|
@elements = []
|
10
10
|
end
|
11
11
|
|
12
|
+
# Parse note data
|
13
|
+
# @param params [Hash] data to parse
|
14
|
+
# @return [Note] result of parsing
|
12
15
|
def self.parse(params)
|
13
16
|
note = Note.new
|
14
17
|
note.type = params[:type]
|
@@ -23,10 +26,11 @@ module OoxmlParser
|
|
23
26
|
doc.search(xpath_note).each do |ftr|
|
24
27
|
number = 0
|
25
28
|
ftr.xpath('*').each do |sub_element|
|
26
|
-
|
29
|
+
case sub_element.name
|
30
|
+
when 'p'
|
27
31
|
note.elements << params[:default_paragraph].dup.parse(sub_element, number, params[:default_character], parent: note)
|
28
32
|
number += 1
|
29
|
-
|
33
|
+
when 'tbl'
|
30
34
|
note.elements << Table.new(parent: note).parse(sub_element, number)
|
31
35
|
number += 1
|
32
36
|
end
|
@@ -7,6 +7,9 @@ require_relative 'docx_data/document_structure'
|
|
7
7
|
module OoxmlParser
|
8
8
|
# Basic class for DocxParser
|
9
9
|
class DocxParser
|
10
|
+
# Parse docx file
|
11
|
+
# @param path_to_file [String] file path
|
12
|
+
# @return [DocumentStructure] result of parse
|
10
13
|
def self.parse_docx(path_to_file)
|
11
14
|
Parser.parse_format(path_to_file) do
|
12
15
|
DocumentStructure.parse
|
data/lib/ooxml_parser/name.rb
CHANGED
@@ -14,6 +14,9 @@ module OoxmlParser
|
|
14
14
|
@color_scheme = color_scheme
|
15
15
|
end
|
16
16
|
|
17
|
+
# Parse PresentationTheme
|
18
|
+
# @param file [String] path to file to parse
|
19
|
+
# @return [PresentationTheme] result of parsing
|
17
20
|
def self.parse(file)
|
18
21
|
OOXMLDocumentObject.theme = PresentationTheme.new
|
19
22
|
OOXMLDocumentObject.add_to_xmls_stack(file)
|
@@ -3,8 +3,8 @@
|
|
3
3
|
require_relative 'slide/presentation_alternate_content'
|
4
4
|
require_relative 'slide/background'
|
5
5
|
require_relative 'slide/common_slide_data'
|
6
|
-
require_relative 'slide/connection_shape
|
7
|
-
require_relative 'slide/presentation_notes
|
6
|
+
require_relative 'slide/connection_shape'
|
7
|
+
require_relative 'slide/presentation_notes'
|
8
8
|
require_relative 'slide/graphic_frame/graphic_frame'
|
9
9
|
require_relative 'slide/slide/shapes_grouping'
|
10
10
|
require_relative 'slide/slide/timing'
|
@@ -28,6 +28,7 @@ module OoxmlParser
|
|
28
28
|
@xml_path = xml_path
|
29
29
|
end
|
30
30
|
|
31
|
+
# @return [True, False] is slide with data
|
31
32
|
def with_data?
|
32
33
|
return true unless background.nil?
|
33
34
|
|
@@ -37,10 +38,12 @@ module OoxmlParser
|
|
37
38
|
false
|
38
39
|
end
|
39
40
|
|
41
|
+
# @return <Array> List of elements on slide
|
40
42
|
def elements
|
41
43
|
@common_slide_data.shape_tree.elements
|
42
44
|
end
|
43
45
|
|
46
|
+
# @return [Background] background of slide
|
44
47
|
def background
|
45
48
|
@common_slide_data.background
|
46
49
|
end
|
@@ -30,6 +30,9 @@ module OoxmlParser
|
|
30
30
|
self
|
31
31
|
end
|
32
32
|
|
33
|
+
# Parse list of timing nodes
|
34
|
+
# @param timing_list_node [Nokogiri::XML::Element] node to parse
|
35
|
+
# @return [Array<TimeNode>] list of nodes
|
33
36
|
def self.parse_list(timing_list_node)
|
34
37
|
timings = []
|
35
38
|
timing_list_node.xpath('*').each do |time_node|
|
@@ -3,10 +3,12 @@
|
|
3
3
|
module OoxmlParser
|
4
4
|
# Methods to help working with slide data
|
5
5
|
module SlideHelper
|
6
|
+
# @return [Array] list of not empty element on slide
|
6
7
|
def nonempty_elements
|
7
8
|
elements.reject { |cur_shape| cur_shape.text_body.paragraphs.first.characters.empty? }
|
8
9
|
end
|
9
10
|
|
11
|
+
# @return [Array<GraphicFrame>] list GraphicFrame elements on slide
|
10
12
|
def graphic_frames
|
11
13
|
elements.select { |cur_element| cur_element.is_a?(GraphicFrame) }
|
12
14
|
end
|
@@ -17,7 +19,7 @@ module OoxmlParser
|
|
17
19
|
def transform_of_object(object)
|
18
20
|
case object
|
19
21
|
when :image
|
20
|
-
elements.find { |e| e.is_a?
|
22
|
+
elements.find { |e| e.is_a? DocxPicture }.properties.transform
|
21
23
|
when :chart
|
22
24
|
elements.find { |e| e.is_a? GraphicFrame }.transform
|
23
25
|
when :table
|
@@ -29,6 +31,10 @@ module OoxmlParser
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
34
|
+
# Get horizontal align of object on slide
|
35
|
+
# @param object [Symbol] object to get
|
36
|
+
# @param slide_size [SlideSize] size of slide
|
37
|
+
# @return [Symbol] type of align
|
32
38
|
def content_horizontal_align(object, slide_size)
|
33
39
|
transform = transform_of_object(object)
|
34
40
|
return :left if transform.offset.x.zero?
|
@@ -38,6 +44,10 @@ module OoxmlParser
|
|
38
44
|
:unknown
|
39
45
|
end
|
40
46
|
|
47
|
+
# Get vertical align of object on slide
|
48
|
+
# @param object [Symbol] object to get
|
49
|
+
# @param slide_size [SlideSize] size of slide
|
50
|
+
# @return [Symbol] type of align
|
41
51
|
def content_vertical_align(object, slide_size)
|
42
52
|
transform = transform_of_object(object)
|
43
53
|
return :top if transform.offset.y.zero?
|
@@ -47,6 +57,10 @@ module OoxmlParser
|
|
47
57
|
:unknown
|
48
58
|
end
|
49
59
|
|
60
|
+
# Get content distribution of object
|
61
|
+
# @param object [Symbol] object to get
|
62
|
+
# @param slide_size [SlideSize] size of slide
|
63
|
+
# @return [Array<Symbol>] type of align
|
50
64
|
def content_distribute(object, slide_size)
|
51
65
|
return %i[horizontally vertically] if content_horizontal_align(object, slide_size) == :center && content_vertical_align(object, slide_size) == :middle
|
52
66
|
return [:horizontally] if content_horizontal_align(object, slide_size) == :center
|
@@ -7,6 +7,9 @@ module OoxmlParser
|
|
7
7
|
class Transition < OOXMLDocumentObject
|
8
8
|
attr_accessor :speed, :properties, :sound_action, :advance_on_click, :delay, :duration
|
9
9
|
|
10
|
+
# Parse Transition object
|
11
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
12
|
+
# @return [Transition] result of parsing
|
10
13
|
def parse(node)
|
11
14
|
node.xpath('*').each do |node_child|
|
12
15
|
@properties = TransitionProperties.new(parent: self).parse(node_child)
|
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'pptx_data/presentation
|
3
|
+
require_relative 'pptx_data/presentation'
|
4
4
|
|
5
5
|
module OoxmlParser
|
6
6
|
# Basic class for parsing pptx
|
7
7
|
class PptxParser
|
8
|
+
# Parse pptx file
|
9
|
+
# @param path_to_file [String] file path
|
10
|
+
# @return [Presentation] result of parse
|
8
11
|
def self.parse_pptx(path_to_file)
|
9
12
|
Parser.parse_format(path_to_file) do
|
10
13
|
Presentation.new.parse
|
data/lib/ooxml_parser/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'workbook/chartsheet'
|
4
|
+
require_relative 'workbook/pivot_cache'
|
4
5
|
require_relative 'workbook/shared_string_table'
|
5
6
|
require_relative 'workbook/style_sheet'
|
6
7
|
require_relative 'workbook/worksheet'
|
@@ -18,12 +19,20 @@ module OoxmlParser
|
|
18
19
|
attr_accessor :style_sheet
|
19
20
|
# @return [SharedStringTable] styles of book
|
20
21
|
attr_accessor :shared_strings_table
|
22
|
+
# @return [Array<PivotCache>] list of pivot caches
|
23
|
+
attr_accessor :pivot_caches
|
21
24
|
|
22
25
|
def initialize(params = {})
|
23
26
|
@worksheets = []
|
27
|
+
@pivot_caches = []
|
24
28
|
super
|
25
29
|
end
|
26
30
|
|
31
|
+
# Return cell by coordinates
|
32
|
+
# @param column [String, Integer] number or numeric digit of column
|
33
|
+
# @param row [Integer] row to find
|
34
|
+
# @param sheet [Integer] number of sheet
|
35
|
+
# @return [XlsxCell] result
|
27
36
|
def cell(column, row, sheet = 0)
|
28
37
|
column = Coordinates.new(row, column).column_number unless StringHelper.numeric?(column.to_s)
|
29
38
|
|
@@ -88,6 +97,8 @@ module OoxmlParser
|
|
88
97
|
@shared_strings_table = SharedStringTable.new(parent: self).parse(shared_string_file)
|
89
98
|
end
|
90
99
|
|
100
|
+
# Parse content of Workbook
|
101
|
+
# @return [XLSXWorkbook]
|
91
102
|
def parse
|
92
103
|
@content_types = ContentTypes.new(parent: self).parse
|
93
104
|
@relationships = Relationships.new(parent: self).parse_file("#{OOXMLDocumentObject.path_to_folder}xl/_rels/workbook.xml.rels")
|
@@ -95,10 +106,10 @@ module OoxmlParser
|
|
95
106
|
OOXMLDocumentObject.xmls_stack = []
|
96
107
|
OOXMLDocumentObject.root_subfolder = 'xl/'
|
97
108
|
OOXMLDocumentObject.add_to_xmls_stack('xl/workbook.xml')
|
98
|
-
doc = Nokogiri::XML.parse(File.open(OOXMLDocumentObject.current_xml))
|
109
|
+
@doc = Nokogiri::XML.parse(File.open(OOXMLDocumentObject.current_xml))
|
99
110
|
@theme = PresentationTheme.parse("xl/#{link_to_theme_xml}") if link_to_theme_xml
|
100
111
|
@style_sheet = StyleSheet.new(parent: self).parse
|
101
|
-
doc.xpath('xmlns:workbook/xmlns:sheets/xmlns:sheet').each do |sheet|
|
112
|
+
@doc.xpath('xmlns:workbook/xmlns:sheets/xmlns:sheet').each do |sheet|
|
102
113
|
file = @relationships.target_by_id(sheet.attribute('id').value)
|
103
114
|
if file.start_with?('worksheets')
|
104
115
|
@worksheets << Worksheet.new(parent: self).parse(file)
|
@@ -107,6 +118,7 @@ module OoxmlParser
|
|
107
118
|
@worksheets << Chartsheet.new(parent: self).parse(file)
|
108
119
|
end
|
109
120
|
end
|
121
|
+
parse_pivot_cache
|
110
122
|
OOXMLDocumentObject.xmls_stack.pop
|
111
123
|
self
|
112
124
|
end
|
@@ -116,5 +128,12 @@ module OoxmlParser
|
|
116
128
|
def link_to_theme_xml
|
117
129
|
relationships.target_by_type('theme').first
|
118
130
|
end
|
131
|
+
|
132
|
+
# Perform parsing of pivot cache
|
133
|
+
def parse_pivot_cache
|
134
|
+
@doc.xpath('xmlns:workbook/xmlns:pivotCaches/xmlns:pivotCache').each do |pivot_cache|
|
135
|
+
@pivot_caches << PivotCache.new(parent: self).parse(pivot_cache)
|
136
|
+
end
|
137
|
+
end
|
119
138
|
end
|
120
139
|
end
|