openxml-docx 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/examples/drawing-ml +134 -0
- data/examples/table +28 -0
- data/lib/openxml/docx.rb +9 -0
- data/lib/openxml/docx/attribute_builder.rb +17 -4
- data/lib/openxml/docx/elements/absolute_position_tab.rb +4 -19
- data/lib/openxml/docx/elements/bidi_embed.rb +1 -10
- data/lib/openxml/docx/elements/bidi_override.rb +1 -9
- data/lib/openxml/docx/elements/break.rb +3 -14
- data/lib/openxml/docx/elements/control.rb +5 -2
- data/lib/openxml/docx/elements/deleted_text.rb +1 -1
- data/lib/openxml/docx/elements/drawing.rb +9 -0
- data/lib/openxml/docx/elements/element.rb +2 -1
- data/lib/openxml/docx/elements/embed_bold.rb +25 -0
- data/lib/openxml/docx/elements/embed_bold_italic.rb +25 -0
- data/lib/openxml/docx/elements/embed_italic.rb +25 -0
- data/lib/openxml/docx/elements/embed_regular.rb +25 -0
- data/lib/openxml/docx/elements/family.rb +22 -0
- data/lib/openxml/docx/elements/font.rb +14 -0
- data/lib/openxml/docx/elements/grid_column.rb +2 -2
- data/lib/openxml/docx/elements/group_shape.rb +10 -0
- data/lib/openxml/docx/elements/markup_compatibility_alternate_content.rb +10 -0
- data/lib/openxml/docx/elements/markup_compatibility_choice.rb +13 -0
- data/lib/openxml/docx/elements/markup_compatibility_fallback.rb +10 -0
- data/lib/openxml/docx/elements/paper_source.rb +4 -2
- data/lib/openxml/docx/elements/section_properties.rb +9 -0
- data/lib/openxml/docx/elements/symbol.rb +4 -2
- data/lib/openxml/docx/elements/table.rb +1 -1
- data/lib/openxml/docx/elements/table_cell.rb +2 -1
- data/lib/openxml/docx/elements/table_row.rb +7 -5
- data/lib/openxml/docx/elements/text.rb +1 -10
- data/lib/openxml/docx/elements/vml_container.rb +10 -0
- data/lib/openxml/docx/elements/word_processing_drawing_anchor.rb +23 -0
- data/lib/openxml/docx/elements/word_processing_drawing_effect_extent.rb +16 -0
- data/lib/openxml/docx/elements/word_processing_drawing_extent.rb +14 -0
- data/lib/openxml/docx/elements/word_processing_drawing_nv_graphic_frame_properties.rb +11 -0
- data/lib/openxml/docx/elements/word_processing_drawing_object_nv_properties.rb +17 -0
- data/lib/openxml/docx/elements/word_processing_drawing_position_h.rb +23 -0
- data/lib/openxml/docx/elements/word_processing_drawing_position_offset.rb +10 -0
- data/lib/openxml/docx/elements/word_processing_drawing_position_v.rb +23 -0
- data/lib/openxml/docx/elements/word_processing_drawing_simple_position.rb +13 -0
- data/lib/openxml/docx/elements/word_processing_drawing_wrap_none.rb +10 -0
- data/lib/openxml/docx/elements/word_processing_shapes_body_properties.rb +58 -0
- data/lib/openxml/docx/elements/word_processing_shapes_shape.rb +12 -0
- data/lib/openxml/docx/elements/word_processing_shapes_shape_properties.rb +23 -0
- data/lib/openxml/docx/package.rb +73 -1
- data/lib/openxml/docx/parts/document.rb +6 -24
- data/lib/openxml/docx/parts/fonts.rb +35 -0
- data/lib/openxml/docx/parts/footer.rb +32 -0
- data/lib/openxml/docx/parts/header.rb +32 -0
- data/lib/openxml/docx/parts/settings.rb +6 -2
- data/lib/openxml/docx/parts/styles.rb +5 -6
- data/lib/openxml/docx/properties.rb +0 -1
- data/lib/openxml/docx/properties/alignment.rb +1 -1
- data/lib/openxml/docx/properties/base_property.rb +13 -0
- data/lib/openxml/docx/properties/border.rb +11 -9
- data/lib/openxml/docx/properties/color.rb +6 -4
- data/lib/openxml/docx/properties/column.rb +4 -2
- data/lib/openxml/docx/properties/columns.rb +6 -4
- data/lib/openxml/docx/properties/complex_property.rb +1 -1
- data/lib/openxml/docx/properties/conditional_formatting.rb +14 -12
- data/lib/openxml/docx/properties/document_grid.rb +4 -10
- data/lib/openxml/docx/properties/east_asian_layout.rb +6 -11
- data/lib/openxml/docx/properties/font.rb +18 -22
- data/lib/openxml/docx/properties/footer_reference.rb +21 -0
- data/lib/openxml/docx/properties/frame.rb +16 -47
- data/lib/openxml/docx/properties/header_reference.rb +21 -0
- data/lib/openxml/docx/properties/indentation.rb +11 -8
- data/lib/openxml/docx/properties/language.rb +5 -3
- data/lib/openxml/docx/properties/latent_styles.rb +9 -6
- data/lib/openxml/docx/properties/latent_styles_exception.rb +9 -6
- data/lib/openxml/docx/properties/line_numbering.rb +5 -11
- data/lib/openxml/docx/properties/manual_width.rb +4 -2
- data/lib/openxml/docx/properties/numbering.rb +4 -2
- data/lib/openxml/docx/properties/page_borders.rb +6 -19
- data/lib/openxml/docx/properties/page_margins.rb +10 -7
- data/lib/openxml/docx/properties/page_numbering.rb +66 -74
- data/lib/openxml/docx/properties/page_size.rb +5 -12
- data/lib/openxml/docx/properties/shading.rb +46 -52
- data/lib/openxml/docx/properties/spacing.rb +9 -14
- data/lib/openxml/docx/properties/table_border.rb +12 -10
- data/lib/openxml/docx/properties/table_cell_border.rb +12 -10
- data/lib/openxml/docx/properties/table_cell_margin.rb +6 -4
- data/lib/openxml/docx/properties/table_cell_spacing.rb +5 -3
- data/lib/openxml/docx/properties/table_cell_width.rb +5 -3
- data/lib/openxml/docx/properties/table_indent.rb +5 -3
- data/lib/openxml/docx/properties/table_layout.rb +2 -4
- data/lib/openxml/docx/properties/table_look.rb +8 -6
- data/lib/openxml/docx/properties/table_p_pr.rb +11 -30
- data/lib/openxml/docx/properties/table_row_height.rb +13 -0
- data/lib/openxml/docx/properties/table_width.rb +5 -3
- data/lib/openxml/docx/properties/underline.rb +13 -12
- data/lib/openxml/docx/properties/wafter.rb +5 -3
- data/lib/openxml/docx/properties/wbefore.rb +5 -3
- data/lib/openxml/docx/root_namespaces.rb +74 -0
- data/lib/openxml/docx/section.rb +2 -0
- data/lib/openxml/docx/style.rb +4 -4
- data/lib/openxml/docx/version.rb +1 -1
- data/lib/openxml/drawingml.rb +17 -0
- data/lib/openxml/drawingml/elements.rb +13 -0
- data/lib/openxml/drawingml/elements/adjust_values_list.rb +11 -0
- data/lib/openxml/drawingml/elements/blip_fill.rb +14 -0
- data/lib/openxml/drawingml/elements/extension.rb +13 -0
- data/lib/openxml/drawingml/elements/extension_list.rb +11 -0
- data/lib/openxml/drawingml/elements/extents.rb +14 -0
- data/lib/openxml/drawingml/elements/graphic.rb +10 -0
- data/lib/openxml/drawingml/elements/graphic_data.rb +12 -0
- data/lib/openxml/drawingml/elements/graphic_frame_locks.rb +17 -0
- data/lib/openxml/drawingml/elements/head_end.rb +28 -0
- data/lib/openxml/drawingml/elements/no_fill.rb +10 -0
- data/lib/openxml/drawingml/elements/non_visual_drawing_properties.rb +17 -0
- data/lib/openxml/drawingml/elements/non_visual_picture_drawing_properties.rb +12 -0
- data/lib/openxml/drawingml/elements/non_visual_picture_properties.rb +10 -0
- data/lib/openxml/drawingml/elements/offset.rb +14 -0
- data/lib/openxml/drawingml/elements/outline.rb +36 -0
- data/lib/openxml/drawingml/elements/picture.rb +10 -0
- data/lib/openxml/drawingml/elements/preset_geometry.rb +210 -0
- data/lib/openxml/drawingml/elements/round.rb +10 -0
- data/lib/openxml/drawingml/elements/shape_guide.rb +40 -0
- data/lib/openxml/drawingml/elements/solid_fill.rb +10 -0
- data/lib/openxml/drawingml/elements/srgb_color.rb +14 -0
- data/lib/openxml/drawingml/elements/tail_end.rb +28 -0
- data/lib/openxml/drawingml/elements/transform_effect.rb +18 -0
- data/lib/openxml/drawingml/elements/wordprocessing_shape_group.rb +11 -0
- data/lib/openxml/vml.rb +17 -0
- data/lib/openxml/vml/elements.rb +13 -0
- data/lib/openxml/vml/elements/group.rb +88 -0
- data/lib/openxml/vml/elements/rectangle.rb +115 -0
- data/lib/openxml/vml/elements/rounded_rectangle.rb +121 -0
- data/openxml-docx.gemspec +1 -1
- data/spec/elements/absolute_position_tab_spec.rb +15 -47
- data/spec/elements/bidi_embed_spec.rb +4 -8
- data/spec/elements/bidi_override_spec.rb +4 -8
- data/spec/elements/break_spec.rb +8 -31
- data/spec/elements/content_part_spec.rb +2 -2
- data/spec/elements/control_spec.rb +6 -6
- data/spec/elements/deleted_text_spec.rb +2 -2
- data/spec/elements/drawing_spec.rb +11 -0
- data/spec/elements/drawingml/adjust_values_list_spec.rb +8 -0
- data/spec/elements/drawingml/blip_fill_spec.rb +34 -0
- data/spec/elements/drawingml/extension_list_spec.rb +8 -0
- data/spec/elements/drawingml/extension_spec.rb +19 -0
- data/spec/elements/drawingml/extents_spec.rb +33 -0
- data/spec/elements/drawingml/graphic_data_spec.rb +19 -0
- data/spec/elements/drawingml/graphic_frame_locks_spec.rb +78 -0
- data/spec/elements/drawingml/graphic_spec.rb +8 -0
- data/spec/elements/drawingml/head_end_spec.rb +45 -0
- data/spec/elements/drawingml/no_fill_spec.rb +8 -0
- data/spec/elements/drawingml/non_visual_drawing_properties_spec.rb +63 -0
- data/spec/elements/drawingml/non_visual_picture_drawing_properties_spec.rb +18 -0
- data/spec/elements/drawingml/non_visual_picture_properties_spec.rb +8 -0
- data/spec/elements/drawingml/offset_spec.rb +32 -0
- data/spec/elements/drawingml/outline_spec.rb +58 -0
- data/spec/elements/drawingml/picture_spec.rb +8 -0
- data/spec/elements/drawingml/preset_geometry_spec.rb +19 -0
- data/spec/elements/drawingml/round_spec.rb +8 -0
- data/spec/elements/drawingml/shape_guide_spec.rb +49 -0
- data/spec/elements/drawingml/solid_fill_spec.rb +8 -0
- data/spec/elements/drawingml/srgb_color_spec.rb +20 -0
- data/spec/elements/drawingml/tail_end_spec.rb +44 -0
- data/spec/elements/drawingml/transform_effect_spec.rb +80 -0
- data/spec/elements/drawingml/wordprocessing_shape_group_spec.rb +12 -0
- data/spec/elements/group_shape_spec.rb +11 -0
- data/spec/elements/markup_compatibility_alternate_content_spec.rb +11 -0
- data/spec/elements/markup_compatibility_choice_spec.rb +22 -0
- data/spec/elements/markup_compatibility_fallback_spec.rb +11 -0
- data/spec/elements/section_properties_spec.rb +12 -0
- data/spec/elements/symbol_spec.rb +4 -7
- data/spec/elements/text_spec.rb +2 -2
- data/spec/elements/vml/group_spec.rb +542 -0
- data/spec/elements/vml/rectangle_spec.rb +739 -0
- data/spec/elements/vml/rounded_rectangle_spec.rb +656 -0
- data/spec/elements/vml_container_spec.rb +11 -0
- data/spec/elements/word_processing_drawing_anchor_spec.rb +40 -0
- data/spec/elements/word_processing_drawing_effect_extent_spec.rb +57 -0
- data/spec/elements/word_processing_drawing_extent_spec.rb +34 -0
- data/spec/elements/word_processing_drawing_nv_graphic_frame_properties_spec.rb +11 -0
- data/spec/elements/word_processing_drawing_object_nv_properties_spec.rb +67 -0
- data/spec/elements/word_processing_drawing_position_h_spec.rb +21 -0
- data/spec/elements/word_processing_drawing_position_v_spec.rb +21 -0
- data/spec/elements/word_processing_drawing_simple_position_spec.rb +34 -0
- data/spec/elements/word_processing_drawing_wrap_none_spec.rb +12 -0
- data/spec/elements/word_processing_shapes_body_properties_spec.rb +223 -0
- data/spec/elements/word_processing_shapes_shape_properties_spec.rb +21 -0
- data/spec/elements/word_processing_shapes_shape_spec.rb +23 -0
- data/spec/parts/footer_spec.rb +33 -0
- data/spec/parts/header_spec.rb +33 -0
- data/spec/properties/footer_reference_spec.rb +32 -0
- data/spec/properties/header_reference_spec.rb +32 -0
- data/spec/properties/page_numbering_spec.rb +1 -1
- data/spec/properties/{table_cell_fit_text.rb → table_cell_fit_text_spec.rb} +0 -0
- data/spec/properties/{table_cell_width.rb → table_cell_width_spec.rb} +0 -0
- data/spec/properties/table_layout_spec.rb +14 -12
- data/spec/properties/{table_row_height.rb → table_row_height_spec.rb} +0 -0
- data/spec/section_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/data/elements/grid_column_element.xml +1 -1
- data/spec/support/data/elements/table_grid_element.xml +1 -1
- data/spec/support/data/parts/document_with_children_part.xml +2 -1
- data/spec/support/data/parts/document_with_multiple_sections_part.xml +1 -1
- data/spec/support/data/parts/document_with_one_section_part.xml +1 -1
- data/spec/support/data/parts/empty_document_part.xml +1 -1
- data/spec/support/data/parts/empty_footer_part.xml +1 -0
- data/spec/support/data/parts/empty_header_part.xml +1 -0
- data/spec/support/data/parts/footer_with_children_part.xml +1 -0
- data/spec/support/data/parts/header_with_children_part.xml +1 -0
- data/spec/support/element_test_macros.rb +58 -9
- metadata +126 -9
- data/lib/openxml/docx/properties/tr_height.rb +0 -19
- data/lib/openxml/docx/properties/width_property.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 721596bd0a99e7649d104985afa53b7152101fa6
|
4
|
+
data.tar.gz: e956ff4f80b2ce46f3022e5a05f92bb99e7057ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbfecbf3a5aa07b90d1909c0642926dc025cafd08866f75b283768c3b7e0943b88a29737bcd92a0e4de90e29a1011f35d9fdc8514480157f1238d67c8b91caf5
|
7
|
+
data.tar.gz: a0aeb4b5b1032e62f3531498e9d3ffe4e27ef4e7834d41e80917fcb4edfa57c0eabbd4cfed81688245f8f30476a739f9da76d4bae7a38f7e9ea8f7ec78d0f8bc
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
openxml-docx (0.
|
4
|
+
openxml-docx (0.10.0)
|
5
5
|
nokogiri
|
6
|
-
openxml-package (>= 0.2.
|
6
|
+
openxml-package (>= 0.2.2)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
mini_portile2 (2.0.0)
|
17
17
|
nokogiri (1.6.7)
|
18
18
|
mini_portile2 (~> 2.0.0.rc2)
|
19
|
-
openxml-package (0.2.
|
19
|
+
openxml-package (0.2.2)
|
20
20
|
nokogiri
|
21
21
|
ox
|
22
22
|
rubyzip (~> 1.1.0)
|
@@ -41,7 +41,7 @@ GEM
|
|
41
41
|
rspec-support (~> 3.4.0)
|
42
42
|
rspec-support (3.4.1)
|
43
43
|
rubyzip (1.1.7)
|
44
|
-
simplecov (0.11.
|
44
|
+
simplecov (0.11.1)
|
45
45
|
docile (~> 1.1.0)
|
46
46
|
json (~> 1.8)
|
47
47
|
simplecov-html (~> 0.10.0)
|
data/examples/drawing-ml
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.push Dir.pwd + "/lib"
|
4
|
+
require "openxml/docx"
|
5
|
+
require "openxml/vml"
|
6
|
+
|
7
|
+
include OpenXml::Docx::Elements
|
8
|
+
|
9
|
+
document = OpenXml::Docx::Package.new
|
10
|
+
|
11
|
+
table = Table.new
|
12
|
+
table.table_width.type = :auto
|
13
|
+
table.table_width.width = 0
|
14
|
+
table.table_layout = :fixed
|
15
|
+
|
16
|
+
table_cell_margins = OpenXml::Docx::Properties::TableCellMargins.new
|
17
|
+
start_margin = OpenXml::Docx::Properties::TableCellMargin.new(:start)
|
18
|
+
end_margin = OpenXml::Docx::Properties::TableCellMargin.new(:end)
|
19
|
+
start_margin.type = :dxa
|
20
|
+
start_margin.width = 86
|
21
|
+
end_margin.type = :dxa
|
22
|
+
end_margin.width = 86
|
23
|
+
table_cell_margins << start_margin
|
24
|
+
table_cell_margins << end_margin
|
25
|
+
|
26
|
+
table << table_cell_margins
|
27
|
+
|
28
|
+
table.table_look.firstColumn = false
|
29
|
+
table.table_look.firstRow = false
|
30
|
+
table.table_look.lastColumn = false
|
31
|
+
table.table_look.lastRow = false
|
32
|
+
table.table_look.noHBand = false
|
33
|
+
table.table_look.noVBand = false
|
34
|
+
|
35
|
+
table_grid = TableGrid.new
|
36
|
+
[3787, 172, 3787, 172, 3787].each do |width|
|
37
|
+
grid_column = GridColumn.new
|
38
|
+
grid_column.w = width
|
39
|
+
table_grid << grid_column
|
40
|
+
end
|
41
|
+
|
42
|
+
table << table_grid
|
43
|
+
|
44
|
+
table_row = TableRow.new
|
45
|
+
table_row.table_row_height.hRule = :exact
|
46
|
+
table_row.table_row_height.val = 1140
|
47
|
+
|
48
|
+
table_cell = TableCell.new
|
49
|
+
|
50
|
+
table_cell_width = OpenXml::Docx::Properties::TableCellWidth.new
|
51
|
+
table_cell_width.type = :dxa
|
52
|
+
table_cell_width.width = 0
|
53
|
+
table_cell << table_cell_width
|
54
|
+
|
55
|
+
table_cell_margins = OpenXml::Docx::Properties::TableCellMargins.new
|
56
|
+
|
57
|
+
top_margin = OpenXml::Docx::Properties::TableCellMargin.new(:top)
|
58
|
+
top_margin.type = :dxa
|
59
|
+
top_margin.width = 0
|
60
|
+
|
61
|
+
bottom_margin = OpenXml::Docx::Properties::TableCellMargin.new(:bottom)
|
62
|
+
bottom_margin.type = :dxa
|
63
|
+
bottom_margin.width = 0
|
64
|
+
|
65
|
+
table_cell_margins << top_margin
|
66
|
+
table_cell_margins << bottom_margin
|
67
|
+
table_cell << table_cell_margins
|
68
|
+
|
69
|
+
table_cell.v_align = :center
|
70
|
+
|
71
|
+
paragraph = Paragraph.new
|
72
|
+
table_cell << paragraph
|
73
|
+
table_row << table_cell
|
74
|
+
table << table_row
|
75
|
+
document.document << table
|
76
|
+
|
77
|
+
outline_paragraph = Paragraph.new
|
78
|
+
outline_paragraph.spacing.after = 0
|
79
|
+
outline_paragraph.spacing.line = 20
|
80
|
+
outline_paragraph.spacing.line_rule = :exact
|
81
|
+
|
82
|
+
outline_run = Run.new
|
83
|
+
|
84
|
+
vml_container = VmlContainer.new
|
85
|
+
|
86
|
+
round_rectangle = OpenXml::Vml::Elements::RoundedRectangle.new
|
87
|
+
round_rectangle.arc_size = "6554f"
|
88
|
+
round_rectangle.filled = :false
|
89
|
+
round_rectangle.id = "AutoShape_x0020_31"
|
90
|
+
round_rectangle.allow_in_cell = :false
|
91
|
+
round_rectangle.optional_string = "_x0000_s1026"
|
92
|
+
round_rectangle.stroke_color = "#bfbfbf"
|
93
|
+
round_rectangle.stroke_weight = ".25pt"
|
94
|
+
round_rectangle.print = :false
|
95
|
+
style_string = "position:absolute;margin-left:13.55pt;margin-top:36.1pt;width:189.35pt;height:1in;z-index:251642880;visibility:visible;mso-wrap-style:square;mso-width-percent:0;mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;mso-position-horizontal-relative:page;mso-position-vertical:absolute;mso-position-vertical-relative:page;mso-width-percent:0;mso-height-percent:0;mso-width-relative:page;mso-height-relative:page;v-text-anchor:top"
|
96
|
+
round_rectangle.style = style_string
|
97
|
+
|
98
|
+
vml_container << round_rectangle
|
99
|
+
|
100
|
+
outline_run << vml_container
|
101
|
+
|
102
|
+
outline_paragraph << outline_run
|
103
|
+
|
104
|
+
document.document << outline_paragraph
|
105
|
+
|
106
|
+
section_properties = SectionProperties.new
|
107
|
+
|
108
|
+
page_size = OpenXml::Docx::Properties::PageSize.new
|
109
|
+
page_size.height = 15840
|
110
|
+
page_size.width = 12240
|
111
|
+
section_properties << page_size
|
112
|
+
|
113
|
+
page_margin = OpenXml::Docx::Properties::PageMargins.new
|
114
|
+
page_margin.bottom = 600
|
115
|
+
page_margin.footer = 0
|
116
|
+
page_margin.gutter = 0
|
117
|
+
page_margin.header = 0
|
118
|
+
page_margin.left = 367
|
119
|
+
page_margin.right = 446
|
120
|
+
page_margin.top = 720
|
121
|
+
|
122
|
+
section_properties << page_margin
|
123
|
+
|
124
|
+
columns = OpenXml::Docx::Properties::Columns.new
|
125
|
+
columns.space = 720
|
126
|
+
|
127
|
+
section_properties << columns
|
128
|
+
|
129
|
+
document.document << section_properties
|
130
|
+
|
131
|
+
filename = "border_test.docx"
|
132
|
+
system "rm -f ~/Desktop/#{filename}" # -f so that we don't have an error if the file doesn't exist
|
133
|
+
document.save File.expand_path("~/Desktop/#{filename}")
|
134
|
+
exec "open ~/Desktop/#{filename}"
|
data/examples/table
CHANGED
@@ -61,6 +61,34 @@ end
|
|
61
61
|
|
62
62
|
document.document << table
|
63
63
|
|
64
|
+
header = OpenXml::Docx::Parts::Header.new
|
65
|
+
paragraph = Paragraph.new
|
66
|
+
run = Run.new
|
67
|
+
run << Text.new("This is some header text")
|
68
|
+
paragraph << run
|
69
|
+
header << paragraph
|
70
|
+
|
71
|
+
header_id = document.add_header(header)
|
72
|
+
|
73
|
+
footer = OpenXml::Docx::Parts::Footer.new
|
74
|
+
paragraph = Paragraph.new
|
75
|
+
run = Run.new
|
76
|
+
run << Text.new("This is some footer text")
|
77
|
+
paragraph << run
|
78
|
+
footer << paragraph
|
79
|
+
|
80
|
+
footer_id = document.add_footer(footer)
|
81
|
+
|
82
|
+
section = OpenXml::Docx::Section.new
|
83
|
+
section.header_reference.id = header_id
|
84
|
+
section.header_reference.type = :default
|
85
|
+
|
86
|
+
section.footer_reference.id = footer_id
|
87
|
+
section.footer_reference.type = :default
|
88
|
+
|
89
|
+
document.document << section
|
90
|
+
|
91
|
+
|
64
92
|
filename = "rocx_test_table.docx"
|
65
93
|
system "rm -f ~/Desktop/#{filename}" # -f so that we don't have an error if the file doesn't exist
|
66
94
|
document.save File.expand_path("~/Desktop/#{filename}")
|
data/lib/openxml/docx.rb
CHANGED
@@ -3,16 +3,25 @@ module OpenXml
|
|
3
3
|
REL_DOCUMENT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument".freeze
|
4
4
|
REL_STYLES = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles".freeze
|
5
5
|
REL_SETTINGS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings".freeze
|
6
|
+
REL_HEADER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header".freeze
|
7
|
+
REL_FOOTER = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer".freeze
|
8
|
+
REL_FONT_TABLE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable".freeze
|
9
|
+
REL_FONT = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/font".freeze
|
6
10
|
|
7
11
|
TYPE_STYLES = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml".freeze
|
8
12
|
TYPE_SETTINGS = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml".freeze
|
13
|
+
TYPE_HEADER = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml".freeze
|
14
|
+
TYPE_FOOTER = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml".freeze
|
15
|
+
TYPE_FONT_TABLE = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml".freeze
|
9
16
|
TYPE_XML = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml".freeze
|
17
|
+
TYPE_OBSCURED_FONT = "application/vnd.openxmlformats-officedocument.obfuscatedFont".freeze
|
10
18
|
end
|
11
19
|
end
|
12
20
|
|
13
21
|
require "openxml/docx/attribute_builder"
|
14
22
|
require "openxml/docx/property_builder"
|
15
23
|
require "openxml/docx/properties"
|
24
|
+
require "openxml/docx/root_namespaces"
|
16
25
|
require "openxml/docx/elements"
|
17
26
|
require "openxml/docx/package"
|
18
27
|
require "openxml/docx/parts"
|
@@ -203,24 +203,30 @@ module OpenXml
|
|
203
203
|
end
|
204
204
|
|
205
205
|
module ClassMethods
|
206
|
-
def attribute(name, expects: nil, displays_as: nil, namespace: nil)
|
206
|
+
def attribute(name, expects: nil, one_of: nil, displays_as: nil, namespace: nil)
|
207
207
|
bad_names = %w(tag name namespace properties_tag)
|
208
208
|
raise ArgumentError if bad_names.member? name
|
209
209
|
|
210
210
|
attr_reader name
|
211
211
|
|
212
212
|
define_method "#{name}=" do |value|
|
213
|
-
|
213
|
+
valid_in?(value, one_of) unless one_of.nil?
|
214
|
+
send(expects, value) unless expects.nil?
|
214
215
|
instance_variable_set "@#{name}", value
|
215
216
|
end
|
216
217
|
|
217
218
|
camelized_name = name.to_s.gsub(/_([a-z])/i) { $1.upcase }.to_sym
|
218
|
-
attributes[name] = [displays_as || camelized_name, namespace ||
|
219
|
+
attributes[name] = [displays_as || camelized_name, namespace || @attribute_namespace]
|
219
220
|
end
|
220
221
|
|
221
222
|
def attributes
|
222
223
|
@attributes ||= {}
|
223
224
|
end
|
225
|
+
|
226
|
+
def with_namespace(namespace, &block)
|
227
|
+
@attribute_namespace = namespace
|
228
|
+
instance_eval(&block)
|
229
|
+
end
|
224
230
|
end
|
225
231
|
|
226
232
|
def render?
|
@@ -237,7 +243,9 @@ module OpenXml
|
|
237
243
|
attributes.each_with_object({}) do |(name, options), attrs|
|
238
244
|
display, namespace = options
|
239
245
|
value = send(name)
|
240
|
-
|
246
|
+
attr_name = "#{namespace}:#{display}"
|
247
|
+
attr_name = "#{display}" if namespace.nil?
|
248
|
+
attrs[attr_name] = value if value
|
241
249
|
end
|
242
250
|
end
|
243
251
|
|
@@ -276,6 +284,11 @@ module OpenXml
|
|
276
284
|
raise ArgumentError, message if !value.is_a?(String) || value.length.zero?
|
277
285
|
end
|
278
286
|
|
287
|
+
def percentage(value)
|
288
|
+
message = "Invalid #{name}: must be a percentage"
|
289
|
+
raise ArgumentError, message unless value.is_a?(String) && value =~ /-?[0-9]+(\.[0-9]+)?%/ # Regex supplied in sec. 22.9.2.9 of Office Open XML docs
|
290
|
+
end
|
291
|
+
|
279
292
|
def on_or_off(value)
|
280
293
|
valid_in? value, [:on, :off]
|
281
294
|
end
|
@@ -3,26 +3,11 @@ module OpenXml
|
|
3
3
|
module Elements
|
4
4
|
class AbsolutePositionTab < Element
|
5
5
|
tag :ptab
|
6
|
-
attribute :alignment, expects: :valid_ptab_alignment
|
7
|
-
attribute :leader, expects: :valid_ptab_leader
|
8
|
-
attribute :relativeTo, expects: :valid_ptab_relative_to
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def valid_ptab_alignment(value)
|
17
|
-
valid_in? value, VALID_PTAB_ALIGNMENTS
|
18
|
-
end
|
19
|
-
|
20
|
-
def valid_ptab_leader(value)
|
21
|
-
valid_in? value, VALID_PTAB_LEADERS
|
22
|
-
end
|
23
|
-
|
24
|
-
def valid_ptab_relative_to(value)
|
25
|
-
valid_in? value, VALID_PTAB_RELATIVE_TOS
|
7
|
+
with_namespace :w do
|
8
|
+
attribute :alignment, one_of: %i(center left right)
|
9
|
+
attribute :leader, one_of: %i(dot hyphen middleDot none underscore)
|
10
|
+
attribute :relativeTo, one_of: %i(indent margin)
|
26
11
|
end
|
27
12
|
|
28
13
|
end
|
@@ -3,16 +3,7 @@ module OpenXml
|
|
3
3
|
module Elements
|
4
4
|
class BidiEmbed < Container
|
5
5
|
tag :dir
|
6
|
-
attribute :direction,
|
7
|
-
|
8
|
-
VALID_DIRECTIONS = %i(rtl ltr)
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def valid_direction(value)
|
13
|
-
valid_in? value, VALID_DIRECTIONS
|
14
|
-
end
|
15
|
-
|
6
|
+
attribute :direction, one_of: %i(rtl ltr), displays_as: :val, namespace: :w
|
16
7
|
end
|
17
8
|
end
|
18
9
|
end
|
@@ -3,15 +3,7 @@ module OpenXml
|
|
3
3
|
module Elements
|
4
4
|
class BidiOverride < Container
|
5
5
|
tag :bdo
|
6
|
-
attribute :direction,
|
7
|
-
|
8
|
-
VALID_DIRECTIONS = %i(rtl ltr)
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def valid_direction(value)
|
13
|
-
valid_in? value, VALID_DIRECTIONS
|
14
|
-
end
|
6
|
+
attribute :direction, one_of: %i(rtl ltr), displays_as: :val, namespace: :w
|
15
7
|
|
16
8
|
end
|
17
9
|
end
|
@@ -4,20 +4,9 @@ module OpenXml
|
|
4
4
|
class Break < Element
|
5
5
|
tag :br
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
VALID_CLEARS = %i(all left none right)
|
11
|
-
VALID_BREAK_TYPES = %i(column page textWrapping)
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def valid_clear(value)
|
16
|
-
valid_in? value, VALID_CLEARS
|
17
|
-
end
|
18
|
-
|
19
|
-
def valid_break_type(value)
|
20
|
-
valid_in? value, VALID_BREAK_TYPES
|
7
|
+
with_namespace :w do
|
8
|
+
attribute :clear, one_of: %i(all left none right)
|
9
|
+
attribute :type, one_of: %i(column page textWrapping)
|
21
10
|
end
|
22
11
|
|
23
12
|
end
|
@@ -3,8 +3,11 @@ module OpenXml
|
|
3
3
|
module Elements
|
4
4
|
class Control < Element
|
5
5
|
attribute :id, expects: :string, namespace: :r
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
with_namespace :w do
|
8
|
+
attribute :unique_name, expects: :string, displays_as: :name
|
9
|
+
attribute :shape_id, expects: :string, displays_as: :shapeid
|
10
|
+
end
|
8
11
|
|
9
12
|
end
|
10
13
|
end
|
@@ -6,6 +6,7 @@ module OpenXml
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
attr_reader :property_name
|
9
|
+
attr_reader :namespace
|
9
10
|
|
10
11
|
def tag(*args)
|
11
12
|
@tag = args.first if args.any?
|
@@ -37,7 +38,7 @@ module OpenXml
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def to_xml(xml)
|
40
|
-
xml[
|
41
|
+
xml[namespace].public_send(tag, xml_attributes)
|
41
42
|
end
|
42
43
|
|
43
44
|
private
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Elements
|
4
|
+
class EmbedBold < Element
|
5
|
+
namespace :w
|
6
|
+
|
7
|
+
with_namespace :w do
|
8
|
+
attribute :font_key, expects: :bracketed_guid, displays_as: :fontKey
|
9
|
+
attribute :subsetted, expects: :true_or_false
|
10
|
+
end
|
11
|
+
|
12
|
+
attribute :relationship_id, expects: :string, displays_as: :id, namespace: :r
|
13
|
+
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def bracketed_guid(value)
|
18
|
+
guid_regex = /\{[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{12}\}/ # Regex taken from spec section 22.9.2.4
|
19
|
+
raise ArgumentError, "Not a validly-formatted GUID" unless value =~ guid_regex
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|