ooxml_parser 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/ooxml_parser.rb +2 -0
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/chart/chart.rb +3 -2
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb +2 -1
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/borders_properties.rb +11 -8
- data/lib/ooxml_parser/common_parser/common_data/colors/hsl_color.rb +12 -15
- data/lib/ooxml_parser/common_parser/common_data/colors/image/stretching.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/image/{fill_rectangle.rb → stretching/fill_rectangle.rb} +0 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/image_fill.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color.rb +1 -2
- data/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color/linear_gradient.rb +10 -0
- data/lib/ooxml_parser/common_parser/common_data/hyperlink.rb +6 -1
- data/lib/ooxml_parser/common_parser/common_data/ooxml_document_object.rb +29 -1
- data/lib/ooxml_parser/common_parser/common_data/paragraph.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties.rb +1 -1
- data/lib/ooxml_parser/{pptx_parser/pptx_data/presentation/slide/shape/text_body → common_parser/common_data/paragraph}/text_field.rb +0 -0
- data/lib/ooxml_parser/common_parser/common_data/relationships.rb +31 -0
- data/lib/ooxml_parser/common_parser/common_data/relationships/relationship.rb +22 -0
- data/lib/ooxml_parser/common_parser/common_data/table.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style.rb +1 -0
- data/lib/ooxml_parser/common_parser/common_data/table/properties/table_style_elements.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/cell_properties.rb +39 -96
- data/lib/ooxml_parser/common_parser/common_data/table/row/cell/merge.rb +7 -3
- data/lib/ooxml_parser/common_parser/common_data/table/row/row/table_row_properties.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/table/table_grid.rb +1 -1
- data/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb +5 -2
- data/lib/ooxml_parser/common_parser/common_data/table/table_properties/table_borders.rb +33 -0
- data/lib/ooxml_parser/common_parser/parser.rb +17 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure.rb +15 -26
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb +26 -0
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_properties.rb +6 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run.rb +5 -5
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape.rb +9 -10
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/frame_properties.rb +1 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/document_grid.rb +1 -1
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/page_properties/page_properties.rb +6 -13
- data/lib/ooxml_parser/docx_parser/docx_parser.rb +3 -7
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation.rb +1 -2
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_comment/presentation_comment_author.rb +2 -1
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/presentation_theme.rb +1 -1
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide.rb +13 -19
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/animation_effect/animation_effect.rb +2 -2
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/behavior/behavior.rb +1 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/set_time_node/set_time_node.rb +2 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node.rb +2 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node/common_timing/condition.rb +2 -2
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition.rb +3 -14
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/{sound_action → transition}/sound_action.rb +2 -0
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/{sound_action/sound → transition/sound_action}/sound.rb +1 -2
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/transition/transition_properties/transition_properties.rb +20 -0
- data/lib/ooxml_parser/pptx_parser/pptx_parser.rb +3 -7
- data/lib/ooxml_parser/version.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook.rb +4 -3
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb +12 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row.rb +1 -1
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb +2 -2
- data/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/ooxml_font.rb +2 -4
- data/lib/ooxml_parser/xlsx_parser/xlsx_parser.rb +3 -7
- metadata +10 -16
- data/.overcommit.yml +0 -35
- data/Changelog.md +0 -25
- data/circle.yml +0 -3
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/offset.rb +0 -10
- data/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_paragraph_run/shape/shadow.rb +0 -10
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/shape_properties/extents.rb +0 -10
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/shape_properties/offset.rb +0 -10
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shape/text_body/paragraph.rb +0 -10
- data/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/shapes_grouping/shapes_grouping.rb +0 -9
- data/ooxml_parser.gemspec +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f40b6ee146d2fa4c06246636b63931ec3c178a2c
|
4
|
+
data.tar.gz: 08e151b4a17546c6787000bac1d727687ff6f5b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15187c6a9a8ac851637a1d9bfaa1f69cb651f6d22533fa66cb3b1c97c6960494daa6e3a82a2c38fec149c9c7d117289dc946273ee5b2626927b60627986f9b67
|
7
|
+
data.tar.gz: a1bfd37779ec4e6003a71e90f5eaed425eeca04bfb7d849e523f21b567413ad958fb227acb55cf7a15d3d97590e391a590953207451b880751e7b0d4b70fb075
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ _ooxml_parser_ is a Ooxml files (docx, xlsx, pptx) parser written in Ruby.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
$ gem install
|
7
|
+
$ gem install ooxml_parser
|
8
8
|
|
9
9
|
## Usage
|
10
10
|
|
@@ -23,4 +23,4 @@ Default is `:centimeters`
|
|
23
23
|
|
24
24
|
OoxmlParser.configure do |config|
|
25
25
|
config.units = :points
|
26
|
-
end
|
26
|
+
end
|
data/lib/ooxml_parser.rb
CHANGED
@@ -9,6 +9,8 @@ require_relative 'ooxml_parser/common_parser/common_data/paragraph'
|
|
9
9
|
require_relative 'ooxml_parser/common_parser/common_data/alternate_content/alternate_content'
|
10
10
|
require_relative 'ooxml_parser/common_parser/common_data/colors/presentation_fill'
|
11
11
|
require_relative 'ooxml_parser/common_parser/common_data/table'
|
12
|
+
require_relative 'ooxml_parser/common_parser/common_data/relationships'
|
13
|
+
require_relative 'ooxml_parser/common_parser/parser'
|
12
14
|
require_relative 'ooxml_parser/common_parser/common_document_structure'
|
13
15
|
require_relative 'ooxml_parser/configuration'
|
14
16
|
require_relative 'ooxml_parser/helpers/string_helper'
|
@@ -31,9 +31,10 @@ module OoxmlParser
|
|
31
31
|
when :point, :bubble
|
32
32
|
val = chart_props_node_child.xpath('c:yVal')[0]
|
33
33
|
else
|
34
|
-
|
34
|
+
next
|
35
35
|
end
|
36
|
-
|
36
|
+
next if val.xpath('c:numRef').empty?
|
37
|
+
@data << ChartCellsRange.parse(val.xpath('c:numRef').first).dup
|
37
38
|
when 'dLbls'
|
38
39
|
@display_labels = DisplayLabelsProperties.parse(chart_props_node_child)
|
39
40
|
end
|
@@ -12,6 +12,7 @@ module OoxmlParser
|
|
12
12
|
def self.parse(blip_fill_node)
|
13
13
|
blip = DocxBlip.new
|
14
14
|
blip_node = blip_fill_node.xpath('a:blip', 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main').first
|
15
|
+
return blip if blip_node.nil?
|
15
16
|
path_to_media_file = OOXMLDocumentObject.get_link_from_rels(blip_node.attribute('embed').value)
|
16
17
|
raise LoadError, "Cant find path to media file by id: #{blip_node.attribute('embed').value}" if path_to_media_file.empty?
|
17
18
|
blip_node.xpath('*').each do |blip_node_child|
|
@@ -20,7 +21,7 @@ module OoxmlParser
|
|
20
21
|
blip.alpha_channel = (blip_node_child.attribute('amt').value.to_f / 1_000.0).round(0).to_f
|
21
22
|
end
|
22
23
|
end
|
23
|
-
blip.path_to_media_file = OOXMLDocumentObject.copy_media_file("#{OOXMLDocumentObject.root_subfolder}/#{path_to_media_file.gsub('..', '')}")
|
24
|
+
blip.path_to_media_file = OOXMLDocumentObject.copy_media_file("#{OOXMLDocumentObject.root_subfolder}/#{path_to_media_file.gsub('..', '')}") unless path_to_media_file == 'NULL'
|
24
25
|
blip
|
25
26
|
end
|
26
27
|
end
|
data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/group/old_docx_group.rb
CHANGED
@@ -19,7 +19,7 @@ module OoxmlParser
|
|
19
19
|
element.object = OldDocxShape.parse(group_node_child)
|
20
20
|
group.elements << element
|
21
21
|
when 'wrap'
|
22
|
-
group.properties.wrap = group_node_child.attribute('type').value.to_sym
|
22
|
+
group.properties.wrap = group_node_child.attribute('type').value.to_sym unless group_node_child.attribute('type').nil?
|
23
23
|
when 'group'
|
24
24
|
element = parse(group_node_child)
|
25
25
|
group.elements << element
|
data/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape.rb
CHANGED
@@ -12,7 +12,7 @@ module OoxmlParser
|
|
12
12
|
when 'textbox'
|
13
13
|
shape.text_box = TextBox.parse_list(shape_node_child)
|
14
14
|
when 'imagedata'
|
15
|
-
path_to_image = OOXMLDocumentObject.copy_media_file("#{OOXMLDocumentObject.root_subfolder}/#{get_link_from_rels(shape_node_child.attribute('id').value
|
15
|
+
path_to_image = OOXMLDocumentObject.copy_media_file("#{OOXMLDocumentObject.root_subfolder}/#{get_link_from_rels(shape_node_child.attribute('id').value)}")
|
16
16
|
shape.image = path_to_image
|
17
17
|
when 'fill'
|
18
18
|
shape.fill = OldDocxShapeFill.parse(shape_node_child)
|
@@ -41,16 +41,19 @@ module OoxmlParser
|
|
41
41
|
# @param [Nokogiri::XML:Element] node with BordersProperties
|
42
42
|
# @return [BordersProperties] value of BordersProperties
|
43
43
|
def self.parse(node)
|
44
|
+
return nil if node.attribute('val').value == 'nil'
|
44
45
|
border_properties = BordersProperties.new
|
45
46
|
border_properties.val = node.attribute('val').value.to_sym
|
46
|
-
border_properties.sz = node.attribute('sz').value.to_f / 8.0
|
47
|
-
border_properties.space = (node.attribute('space').value.to_f / 28.34).round(3)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
border_properties.color
|
47
|
+
border_properties.sz = node.attribute('sz').value.to_f / 8.0 if node.attribute('sz')
|
48
|
+
border_properties.space = (node.attribute('space').value.to_f / 28.34).round(3) unless node.attribute('space').nil?
|
49
|
+
if node.attribute('color')
|
50
|
+
border_properties.color = node.attribute('color').value
|
51
|
+
unless node.attribute('shadow').nil?
|
52
|
+
border_properties.shadow = node.attribute('shadow').value
|
53
|
+
end
|
54
|
+
if border_properties.color != 'auto'
|
55
|
+
border_properties.color = Color.from_int16(border_properties.color)
|
56
|
+
end
|
54
57
|
end
|
55
58
|
border_properties
|
56
59
|
end
|
@@ -31,12 +31,11 @@ module OoxmlParser
|
|
31
31
|
unless max == min
|
32
32
|
hls_color.s = delta / (255.0 - (255.0 - max - min).abs)
|
33
33
|
|
34
|
-
hls_color.h =
|
35
|
-
when max == red && green >= blue
|
34
|
+
hls_color.h = if max == red && green >= blue
|
36
35
|
60.0 * (green - blue) / delta
|
37
|
-
|
36
|
+
elsif max == red && green < blue
|
38
37
|
60.0 * (green - blue) / delta + 360.0
|
39
|
-
|
38
|
+
elsif max == green
|
40
39
|
60.0 * (blue - red) / delta + 120.0
|
41
40
|
else
|
42
41
|
60.0 * (red - green) / delta + 240.0
|
@@ -52,18 +51,17 @@ module OoxmlParser
|
|
52
51
|
x = chroma * (1 - ((@h / 60.0) % 2.0 - 1).abs)
|
53
52
|
m = @l - chroma / 2.0
|
54
53
|
|
55
|
-
rgb =
|
56
|
-
when @h == 0
|
54
|
+
rgb = if @h == 0
|
57
55
|
Color.new(0, 0, 0)
|
58
|
-
|
56
|
+
elsif @h > 0 && @h < 60
|
59
57
|
Color.new(chroma, x, 0)
|
60
|
-
|
58
|
+
elsif @h > 60 && @h < 120
|
61
59
|
Color.new(x, chroma, 0)
|
62
|
-
|
60
|
+
elsif @h > 120 && @h < 180
|
63
61
|
Color.new(0, chroma, x)
|
64
|
-
|
62
|
+
elsif @h > 180 && @h < 240
|
65
63
|
Color.new(0, x, chroma)
|
66
|
-
|
64
|
+
elsif @h > 240 && @h < 300
|
67
65
|
Color.new(x, 0, chroma)
|
68
66
|
else
|
69
67
|
Color.new(chroma, 0, x)
|
@@ -74,12 +72,11 @@ module OoxmlParser
|
|
74
72
|
def set_color(t1, t2, t3)
|
75
73
|
t3 += 1.0 if t3 < 0
|
76
74
|
t3 -= 1.0 if t3 > 1
|
77
|
-
|
78
|
-
when 6.0 * t3 < 1 then
|
75
|
+
if 6.0 * t3 < 1
|
79
76
|
t2 + (t1 - t2) * 6.0 * t3
|
80
|
-
|
77
|
+
elsif 2.0 * t3 < 1
|
81
78
|
t1
|
82
|
-
|
79
|
+
elsif 3.0 * t3 < 2
|
83
80
|
t2 + (t1 - t2) * ((2.0 / 3.0) - t3) * 6.0
|
84
81
|
else
|
85
82
|
t2
|
File without changes
|
@@ -16,6 +16,7 @@ module OoxmlParser
|
|
16
16
|
blip_fill_node.xpath('*').each do |blip_fill_node_child|
|
17
17
|
case blip_fill_node_child.name
|
18
18
|
when 'blip'
|
19
|
+
next unless blip_fill_node_child.attribute('embed')
|
19
20
|
path_to_original_image = OOXMLDocumentObject.get_link_from_rels(blip_fill_node_child.attribute('embed').value)
|
20
21
|
FileUtils.copy(dir + path_to_original_image, OOXMLDocumentObject.media_folder + File.basename(path_to_original_image))
|
21
22
|
image.path = OOXMLDocumentObject.media_folder + File.basename(path_to_original_image)
|
@@ -25,8 +25,7 @@ module OoxmlParser
|
|
25
25
|
when 'path'
|
26
26
|
gradient_color.path = gradient_fill_node_child.attribute('path').value.to_sym
|
27
27
|
when 'lin'
|
28
|
-
gradient_color.path = LinearGradient.
|
29
|
-
gradient_fill_node_child.attribute('scaled').value.to_i)
|
28
|
+
gradient_color.path = LinearGradient.parse(gradient_fill_node_child)
|
30
29
|
end
|
31
30
|
end
|
32
31
|
gradient_color
|
@@ -6,5 +6,15 @@ module OoxmlParser
|
|
6
6
|
@angle = angle
|
7
7
|
@scaled = scaled
|
8
8
|
end
|
9
|
+
|
10
|
+
# Parse LinearGradient object
|
11
|
+
# @param node [Nokogiri::XML:Element] node to parse
|
12
|
+
# @return [LinearGradient] result of parsing
|
13
|
+
def self.parse(node)
|
14
|
+
gradient = LinearGradient.new
|
15
|
+
gradient.angle = node.attribute('ang').value.to_f / 100_000.0 if node.attribute('ang')
|
16
|
+
gradient.scaled = node.attribute('scaled').value.to_i if node.attribute('scaled')
|
17
|
+
gradient
|
18
|
+
end
|
9
19
|
end
|
10
20
|
end
|
@@ -46,7 +46,12 @@ module OoxmlParser
|
|
46
46
|
hyperlink.link_to = OOXMLDocumentObject.get_link_from_rels(on_click_hyperlink_node.attribute('id').value)
|
47
47
|
end
|
48
48
|
end
|
49
|
-
hyperlink
|
49
|
+
return hyperlink unless on_click_hyperlink_node.attribute('highlightClick')
|
50
|
+
hyperlink.highlight_click = if on_click_hyperlink_node.attribute('highlightClick').value == '1'
|
51
|
+
true
|
52
|
+
else
|
53
|
+
false
|
54
|
+
end
|
50
55
|
hyperlink
|
51
56
|
end
|
52
57
|
end
|
@@ -7,6 +7,15 @@ module OoxmlParser
|
|
7
7
|
class OOXMLDocumentObject
|
8
8
|
DEFAULT_DIRECTORY_FOR_MEDIA = '/tmp'.freeze
|
9
9
|
|
10
|
+
def ==(other)
|
11
|
+
instance_variables.each do |current_attribute|
|
12
|
+
unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
|
13
|
+
return false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
10
19
|
class << self
|
11
20
|
attr_accessor :namespace_prefix
|
12
21
|
attr_accessor :root_subfolder
|
@@ -14,6 +23,20 @@ module OoxmlParser
|
|
14
23
|
attr_accessor :xmls_stack
|
15
24
|
attr_accessor :path_to_folder
|
16
25
|
|
26
|
+
# @param path_to_file [String] file
|
27
|
+
# @return [True, False] Check if file is protected by password on open
|
28
|
+
def encrypted_file?(path_to_file)
|
29
|
+
file_result = `file "#{path_to_file}"`
|
30
|
+
# Support of Encrtypted status in `file` util was introduced in file v5.20
|
31
|
+
# but LTS version of ubuntu before 16.04 uses older `file` and it return `Composite Document`
|
32
|
+
# https://github.com/file/file/blob/master/ChangeLog#L217
|
33
|
+
if file_result.include?('Encrypted') || file_result.include?('Composite Document File V2 Document, No summary info')
|
34
|
+
warn("File #{path_to_file} is encrypted. Can't parse it")
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
17
40
|
def copy_file_and_rename_to_zip(path)
|
18
41
|
file_name = File.basename(path)
|
19
42
|
tmp_folder = "/tmp/office_open_xml_parser_#{SecureRandom.uuid}"
|
@@ -78,8 +101,13 @@ module OoxmlParser
|
|
78
101
|
def copy_media_file(path_to_file)
|
79
102
|
folder_to_save_media = '/tmp/media_from_' + File.basename(OOXMLDocumentObject.path_to_folder)
|
80
103
|
path_to_copied_file = folder_to_save_media + '/' + File.basename(path_to_file)
|
104
|
+
full_path_to_file = OOXMLDocumentObject.path_to_folder + path_to_file
|
105
|
+
unless File.exist?(full_path_to_file)
|
106
|
+
warn "Couldn't find #{full_path_to_file} file on filesystem. Possible problem in original document"
|
107
|
+
return nil
|
108
|
+
end
|
81
109
|
FileUtils.mkdir(folder_to_save_media) unless File.exist?(folder_to_save_media)
|
82
|
-
FileUtils.copy_file(
|
110
|
+
FileUtils.copy_file(full_path_to_file, path_to_copied_file)
|
83
111
|
path_to_copied_file
|
84
112
|
end
|
85
113
|
end
|
@@ -37,7 +37,7 @@ module OoxmlParser
|
|
37
37
|
paragraph_properties.numbering.symbol = properties_element.attribute('char').value
|
38
38
|
when 'buAutoNum'
|
39
39
|
paragraph_properties.numbering.type = properties_element.attribute('type').value.to_sym
|
40
|
-
paragraph_properties.numbering.start_at = properties_element.attribute('startAt').value
|
40
|
+
paragraph_properties.numbering.start_at = properties_element.attribute('startAt').value if properties_element.attribute('startAt')
|
41
41
|
when 'tabLst'
|
42
42
|
paragraph_properties.tabs = ParagraphTab.parse(properties_element)
|
43
43
|
end
|
@@ -55,7 +55,7 @@ module OoxmlParser
|
|
55
55
|
when 'i'
|
56
56
|
character_properties.font_style.italic = OOXMLDocumentObject.option_enabled?(properties_element, 'i')
|
57
57
|
when 'u'
|
58
|
-
character_properties.font_style.underlined = Underline.
|
58
|
+
character_properties.font_style.underlined = Underline.new(:single)
|
59
59
|
when 'vertAlign'
|
60
60
|
character_properties.vertical_align = properties_element.attribute('val').value.to_sym
|
61
61
|
when 'rFont'
|
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'relationships/relationship'
|
2
|
+
module OoxmlParser
|
3
|
+
# Class for describing list of relationships
|
4
|
+
class Relationships
|
5
|
+
# @return [Array, Relationship] array of relationships
|
6
|
+
attr_accessor :relationship
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@relationship = []
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [Array, Column] accessor for relationship
|
13
|
+
def [](key)
|
14
|
+
@relationship[key]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Parse Relationships
|
18
|
+
# @param [Nokogiri::XML:Node] node with Relationships
|
19
|
+
# @return [Relationships] result of parsing
|
20
|
+
def self.parse(node)
|
21
|
+
rels = Relationships.new
|
22
|
+
node.xpath('*').each do |node_children|
|
23
|
+
case node_children.name
|
24
|
+
when 'Relationship'
|
25
|
+
rels.relationship << Relationship.parse(node_children)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
rels
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OoxmlParser
|
2
|
+
# Class for single relationship
|
3
|
+
class Relationship
|
4
|
+
# @return [String] id of relation
|
5
|
+
attr_accessor :id
|
6
|
+
# @return [String] type of relation
|
7
|
+
attr_accessor :type
|
8
|
+
# @return [String] target of relation
|
9
|
+
attr_accessor :target
|
10
|
+
|
11
|
+
# Parse Relationship
|
12
|
+
# @param [Nokogiri::XML:Node] node with Relationship
|
13
|
+
# @return [Relationship] result of parsing
|
14
|
+
def self.parse(node)
|
15
|
+
rel = Relationship.new
|
16
|
+
rel.id = node.attribute('Id').value
|
17
|
+
rel.type = node.attribute('Type').value
|
18
|
+
rel.target = node.attribute('Target').value
|
19
|
+
rel
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -4,7 +4,7 @@ require_relative 'table/table_grid'
|
|
4
4
|
require_relative 'table/margins/table_margins'
|
5
5
|
require_relative 'table/margins/paragraph_margins'
|
6
6
|
module OoxmlParser
|
7
|
-
class Table
|
7
|
+
class Table < OOXMLDocumentObject
|
8
8
|
attr_accessor :grid, :rows, :properties, :number
|
9
9
|
|
10
10
|
def initialize(rows = [])
|
@@ -30,111 +30,54 @@ module OoxmlParser
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
cell_borders = Borders.new
|
33
|
-
|
34
|
-
|
35
|
-
cell_properties_node.xpath('w:vMerge') # TODO: Perform not so stupit check
|
36
|
-
rescue Nokogiri::XML::XPath::SyntaxError
|
37
|
-
parse_w_namespace = false
|
33
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:vMerge").each do |v_merge|
|
34
|
+
cell_properties.merge = CellMerge.parse(v_merge)
|
38
35
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
36
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:vAlign").each do |valign_node|
|
37
|
+
cell_properties.vertical_align = valign_node.attribute('val').value.to_sym
|
38
|
+
end
|
39
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:gridSpan").each do |grid_span|
|
40
|
+
cell_properties.merge = CellMerge.new('horizontal', grid_span.attribute('val').value)
|
41
|
+
end
|
42
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:tcW").each do |table_cell_width|
|
43
|
+
cell_properties.table_cell_width = table_cell_width.attribute('w').value.to_f / 567.5
|
44
|
+
end
|
45
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:tcMar").each do |cell_margins_node|
|
46
|
+
cell_properties.table_cell_margin = TableMargins.parse(cell_margins_node)
|
47
|
+
end
|
48
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:textDirection").each do |text_direction|
|
49
|
+
cell_properties.text_direction = Alignment.parse(text_direction.attribute('val'))
|
50
|
+
end
|
51
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:tcBorders").each do |tc_boders|
|
52
|
+
tc_boders.xpath("#{OOXMLDocumentObject.namespace_prefix}:top").each do |top|
|
53
|
+
cell_borders.top = BordersProperties.parse(top)
|
49
54
|
end
|
50
|
-
|
51
|
-
|
55
|
+
tc_boders.xpath("#{OOXMLDocumentObject.namespace_prefix}:right").each do |right|
|
56
|
+
cell_borders.right = BordersProperties.parse(right)
|
52
57
|
end
|
53
|
-
|
54
|
-
|
58
|
+
tc_boders.xpath("#{OOXMLDocumentObject.namespace_prefix}:left").each do |left|
|
59
|
+
cell_borders.left = BordersProperties.parse(left)
|
55
60
|
end
|
56
|
-
|
57
|
-
|
61
|
+
tc_boders.xpath("#{OOXMLDocumentObject.namespace_prefix}:bottom").each do |bottom|
|
62
|
+
cell_borders.bottom = BordersProperties.parse(bottom)
|
58
63
|
end
|
59
|
-
|
60
|
-
|
61
|
-
top_border = BordersProperties.new
|
62
|
-
top_border.color = top.attribute('color').value
|
63
|
-
if !top.attribute('color').nil? && top.attribute('color').value != 'auto'
|
64
|
-
top_border.color = Color.from_int16(top.attribute('color').value)
|
65
|
-
end
|
66
|
-
top_border.sz = top.attribute('sz').value.to_f / 8.0
|
67
|
-
top_border.val = top.attribute('val').value
|
68
|
-
top_border.space = top.attribute('space').value
|
69
|
-
cell_borders.top = top_border
|
70
|
-
end
|
71
|
-
tc_boders.xpath('w:right').each do |right|
|
72
|
-
right_border = BordersProperties.new
|
73
|
-
right_border.color = right.attribute('color').value
|
74
|
-
if !right.attribute('color').nil? && right.attribute('color').value != 'auto'
|
75
|
-
right_border.color = Color.from_int16(right.attribute('color').value)
|
76
|
-
end
|
77
|
-
right_border.sz = right.attribute('sz').value.to_f / 8.0
|
78
|
-
right_border.val = right.attribute('val').value
|
79
|
-
right_border.space = right.attribute('space').value
|
80
|
-
cell_borders.right = right_border
|
81
|
-
end
|
82
|
-
tc_boders.xpath('w:left').each do |left|
|
83
|
-
left_border = BordersProperties.new
|
84
|
-
left_border.color = left.attribute('color').value
|
85
|
-
if !left.attribute('color').nil? && left.attribute('color').value != 'auto'
|
86
|
-
left_border.color = Color.from_int16(left.attribute('color').value)
|
87
|
-
end
|
88
|
-
left_border.sz = left.attribute('sz').value.to_f / 8.0
|
89
|
-
left_border.val = left.attribute('val').value
|
90
|
-
left_border.space = left.attribute('space').value
|
91
|
-
cell_borders.left = left_border
|
92
|
-
end
|
93
|
-
tc_boders.xpath('w:bottom').each do |bottom|
|
94
|
-
bottom_border = BordersProperties.new
|
95
|
-
bottom_border.color = bottom.attribute('color').value
|
96
|
-
if !bottom.attribute('color').nil? && bottom.attribute('color').value != 'auto'
|
97
|
-
bottom_border.color = Color.from_int16(bottom.attribute('color').value)
|
98
|
-
end
|
99
|
-
bottom_border.sz = bottom.attribute('sz').value.to_f / 8.0
|
100
|
-
bottom_border.val = bottom.attribute('val').value
|
101
|
-
bottom_border.space = bottom.attribute('space').value
|
102
|
-
cell_borders.bottom = bottom_border
|
103
|
-
end
|
104
|
-
tc_boders.xpath('w:tl2br').each do |tl2br|
|
105
|
-
top_left_to_bottom_right = BordersProperties.new
|
106
|
-
top_left_to_bottom_right.color = tl2br.attribute('color').value
|
107
|
-
if !tl2br.attribute('color').nil? && tl2br.attribute('color').value != 'auto'
|
108
|
-
top_left_to_bottom_right.color = Color.from_int16(tl2br.attribute('color').value)
|
109
|
-
end
|
110
|
-
top_left_to_bottom_right.sz = tl2br.attribute('sz').value.to_f / 8.0
|
111
|
-
top_left_to_bottom_right.val = tl2br.attribute('val').value
|
112
|
-
top_left_to_bottom_right.space = tl2br.attribute('space').value
|
113
|
-
cell_borders.top_left_to_bottom_right = top_left_to_bottom_right
|
114
|
-
end
|
115
|
-
tc_boders.xpath('w:tr2bl').each do |tr2bl|
|
116
|
-
top_right_to_bottom_left = BordersProperties.new
|
117
|
-
top_right_to_bottom_left.color = tr2bl.attribute('color').value
|
118
|
-
if !tr2bl.attribute('color').nil? && tr2bl.attribute('color').value != 'auto'
|
119
|
-
top_right_to_bottom_left.color = Color.from_int16(tr2bl.attribute('color').value)
|
120
|
-
end
|
121
|
-
top_right_to_bottom_left.sz = tr2bl.attribute('sz').value.to_f / 8.0
|
122
|
-
top_right_to_bottom_left.val = tr2bl.attribute('val').value
|
123
|
-
top_right_to_bottom_left.space = tr2bl.attribute('space').value
|
124
|
-
cell_borders.top_right_to_bottom_left = top_right_to_bottom_left
|
125
|
-
end
|
64
|
+
tc_boders.xpath("#{OOXMLDocumentObject.namespace_prefix}:tl2br").each do |tl2br|
|
65
|
+
cell_borders.top_left_to_bottom_right = BordersProperties.parse(tl2br)
|
126
66
|
end
|
127
|
-
|
128
|
-
|
129
|
-
if !shd.attribute('fill').nil? && shd.attribute('fill').value != 'auto'
|
130
|
-
cell_properties.shd = Color.from_int16(shd.attribute('fill').value)
|
131
|
-
end
|
67
|
+
tc_boders.xpath("#{OOXMLDocumentObject.namespace_prefix}:tr2bl").each do |tr2bl|
|
68
|
+
cell_borders.top_right_to_bottom_left = BordersProperties.parse(tr2bl)
|
132
69
|
end
|
133
|
-
|
134
|
-
|
135
|
-
|
70
|
+
end
|
71
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:shd").each do |shd|
|
72
|
+
next if shd.attribute('val').value == 'nil'
|
73
|
+
cell_properties.shd = shd.attribute('fill').value
|
74
|
+
if !shd.attribute('fill').nil? && shd.attribute('fill').value != 'auto'
|
75
|
+
cell_properties.shd = Color.from_int16(shd.attribute('fill').value)
|
136
76
|
end
|
137
77
|
end
|
78
|
+
cell_properties_node.xpath("#{OOXMLDocumentObject.namespace_prefix}:fill").each do |fill|
|
79
|
+
cell_properties.fill = DocxColorScheme.parse(fill)
|
80
|
+
end
|
138
81
|
cell_properties.borders_properties = cell_borders
|
139
82
|
cell_properties
|
140
83
|
end
|