openxml-docx 0.8.0 → 0.9.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 +1 -1
- data/{example → examples/base} +1 -1
- data/examples/table +68 -0
- data/lib/openxml/docx/elements/grid_column.rb +12 -0
- data/lib/openxml/docx/elements/table.rb +30 -0
- data/lib/openxml/docx/elements/table_cell.rb +26 -0
- data/lib/openxml/docx/elements/table_grid.rb +10 -0
- data/lib/openxml/docx/elements/table_row.rb +36 -0
- data/lib/openxml/docx/package.rb +3 -0
- data/lib/openxml/docx/properties.rb +2 -0
- data/lib/openxml/docx/properties/base_property.rb +14 -0
- data/lib/openxml/docx/properties/cant_split.rb +8 -0
- data/lib/openxml/docx/properties/columns.rb +2 -0
- data/lib/openxml/docx/properties/grid_after.rb +8 -0
- data/lib/openxml/docx/properties/grid_before.rb +8 -0
- data/lib/openxml/docx/properties/grid_span.rb +8 -0
- data/lib/openxml/docx/properties/header.rb +8 -0
- data/lib/openxml/docx/properties/headers.rb +12 -0
- data/lib/openxml/docx/properties/hidden.rb +8 -0
- data/lib/openxml/docx/properties/hide_mark.rb +8 -0
- data/lib/openxml/docx/properties/no_wrap.rb +8 -0
- data/lib/openxml/docx/properties/table_border.rb +25 -0
- data/lib/openxml/docx/properties/table_borders.rb +13 -0
- data/lib/openxml/docx/properties/table_caption.rb +10 -0
- data/lib/openxml/docx/properties/table_cell_border.rb +25 -0
- data/lib/openxml/docx/properties/table_cell_borders.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_cell_margin.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_fit_text.rb +9 -0
- data/lib/openxml/docx/properties/table_cell_margin.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_margins.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_spacing.rb +13 -0
- data/lib/openxml/docx/properties/table_cell_width.rb +13 -0
- data/lib/openxml/docx/properties/table_description.rb +10 -0
- data/lib/openxml/docx/properties/table_header.rb +10 -0
- data/lib/openxml/docx/properties/table_indent.rb +13 -0
- data/lib/openxml/docx/properties/table_layout.rb +14 -0
- data/lib/openxml/docx/properties/table_look.rb +17 -0
- data/lib/openxml/docx/properties/table_overlap.rb +14 -0
- data/lib/openxml/docx/properties/table_p_pr.rb +41 -0
- data/lib/openxml/docx/properties/table_style.rb +10 -0
- data/lib/openxml/docx/properties/table_width.rb +13 -0
- data/lib/openxml/docx/properties/tr_height.rb +19 -0
- data/lib/openxml/docx/properties/valign.rb +13 -0
- data/lib/openxml/docx/properties/wafter.rb +12 -0
- data/lib/openxml/docx/properties/wbefore.rb +12 -0
- data/lib/openxml/docx/properties/width_property.rb +17 -0
- data/lib/openxml/docx/style.rb +17 -7
- data/lib/openxml/docx/version.rb +1 -1
- data/spec/elements/grid_column_spec.rb +15 -0
- data/spec/elements/table_cell_spec.rb +15 -0
- data/spec/elements/table_grid_spec.rb +17 -0
- data/spec/elements/table_row_spec.rb +18 -0
- data/spec/elements/table_spec.rb +21 -0
- data/spec/properties/border_spec.rb +21 -95
- data/spec/properties/cant_split_spec.rb +23 -0
- data/spec/properties/color_spec.rb +9 -29
- data/spec/properties/column_spec.rb +6 -22
- data/spec/properties/columns_spec.rb +4 -14
- data/spec/properties/conditional_formatting_spec.rb +12 -108
- data/spec/properties/document_grid_spec.rb +12 -53
- data/spec/properties/east_asian_layout_spec.rb +14 -74
- data/spec/properties/font_spec.rb +35 -238
- data/spec/properties/frame_spec.rb +48 -285
- data/spec/properties/grid_after_spec.rb +26 -0
- data/spec/properties/grid_before_spec.rb +26 -0
- data/spec/properties/grid_span_spec.rb +24 -0
- data/spec/properties/header_spec.rb +17 -0
- data/spec/properties/headers_spec.rb +39 -0
- data/spec/properties/hidden_spec.rb +23 -0
- data/spec/properties/hide_mark_spec.rb +23 -0
- data/spec/properties/indentation_spec.rb +32 -136
- data/spec/properties/language_spec.rb +3 -12
- data/spec/properties/latent_styles_exception_spec.rb +7 -22
- data/spec/properties/latent_styles_spec.rb +5 -18
- data/spec/properties/line_numbering_spec.rb +15 -68
- data/spec/properties/manual_width_spec.rb +8 -33
- data/spec/properties/no_wrap_spec.rb +23 -0
- data/spec/properties/numbering_spec.rb +4 -13
- data/spec/properties/page_margins_spec.rb +28 -114
- data/spec/properties/page_numbering_spec.rb +26 -367
- data/spec/properties/page_size_spec.rb +15 -62
- data/spec/properties/paper_source_spec.rb +8 -34
- data/spec/properties/shading_spec.rb +21 -92
- data/spec/properties/spacing_spec.rb +27 -119
- data/spec/properties/table_border_spec.rb +119 -0
- data/spec/properties/table_borders_spec.rb +41 -0
- data/spec/properties/table_caption_spec.rb +17 -0
- data/spec/properties/table_cell_border_spec.rb +119 -0
- data/spec/properties/table_cell_borders_spec.rb +40 -0
- data/spec/properties/table_cell_cell_margin_spec.rb +46 -0
- data/spec/properties/table_cell_fit_text.rb +23 -0
- data/spec/properties/table_cell_margin_spec.rb +40 -0
- data/spec/properties/table_cell_margins_spec.rb +46 -0
- data/spec/properties/table_cell_spacing_spec.rb +21 -0
- data/spec/properties/table_cell_width.rb +21 -0
- data/spec/properties/table_description_spec.rb +17 -0
- data/spec/properties/table_header_spec.rb +23 -0
- data/spec/properties/table_indent_spec.rb +43 -0
- data/spec/properties/table_layout_spec.rb +22 -0
- data/spec/properties/table_look_spec.rb +38 -0
- data/spec/properties/table_overlap_spec.rb +22 -0
- data/spec/properties/table_p_pr_spec.rb +68 -0
- data/spec/properties/table_row_height.rb +20 -0
- data/spec/properties/table_style_spec.rb +17 -0
- data/spec/properties/table_width_spec.rb +21 -0
- data/spec/properties/underline_spec.rb +14 -130
- data/spec/properties/valign_spec.rb +19 -0
- data/spec/properties/wafter_spec.rb +21 -0
- data/spec/properties/wbefore_spec.rb +21 -0
- data/spec/support/data/elements/grid_column_element.xml +4 -0
- data/spec/support/data/elements/table_cell_element.xml +8 -0
- data/spec/support/data/elements/table_element.xml +18 -0
- data/spec/support/data/elements/table_grid_element.xml +6 -0
- data/spec/support/data/elements/table_row_element.xml +13 -0
- data/spec/support/property_test_macros.rb +61 -0
- metadata +86 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1972ebd1b0c107bf2b90517f68e43451dd2ce03e
|
4
|
+
data.tar.gz: 98dccd8c85eee5358beb36727ec4a9d73f2c0631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 932d7911afa2eddb1611f2990a23fe4a6e5729f156d93a45a7c255e5e90eaabb5900d3c619b236320d838fe523676f959170f35b43b6c1b2ac894a12e2819a2f
|
7
|
+
data.tar.gz: 32f62f244add36189be452dd40eb7a5e5521e17139d22fd27562cce63149ae61df95e98dd3fd661d6adc601e0462efef10e8700059946a3eeb8e0a8373205201
|
data/Gemfile.lock
CHANGED
data/{example → examples/base}
RENAMED
@@ -17,7 +17,7 @@ paragraph << run
|
|
17
17
|
|
18
18
|
document.document << paragraph
|
19
19
|
|
20
|
-
filename = "
|
20
|
+
filename = "rocx_test_base.docx"
|
21
21
|
system "rm -f ~/Desktop/#{filename}" # -f so that we don't have an error if the file doesn't exist
|
22
22
|
document.save File.expand_path("~/Desktop/#{filename}")
|
23
23
|
exec "open ~/Desktop/#{filename}"
|
data/examples/table
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# require "rails" # workaround: openxml-package uses `extract_options!`
|
4
|
+
$:.push Dir.pwd + "/lib"
|
5
|
+
require "ox"
|
6
|
+
require "openxml/docx"
|
7
|
+
|
8
|
+
|
9
|
+
def default_table_style
|
10
|
+
style = OpenXml::Docx::Style.new(:table)
|
11
|
+
style.id = "TableGrid"
|
12
|
+
|
13
|
+
table_grid_tags.each do |tag_name|
|
14
|
+
tag = OpenXml::Docx::Properties::TableBorder.new(tag_name, :single)
|
15
|
+
table_border_styles = {width: 4, space: 0, color: "000000"}
|
16
|
+
table_border_styles.each {|key, val| tag.send("#{key}=", val) }
|
17
|
+
style.table.table_borders << tag
|
18
|
+
end
|
19
|
+
|
20
|
+
table_cell_margin_tags.each do |tag_name|
|
21
|
+
tag = OpenXml::Docx::Properties::TableCellMargin.new(tag_name)
|
22
|
+
tag.type = :dxa
|
23
|
+
tag.width = %i(start end).include?(tag_name) ? 108 : 0
|
24
|
+
style.table.table_cell_margins << tag
|
25
|
+
end
|
26
|
+
|
27
|
+
style
|
28
|
+
end
|
29
|
+
|
30
|
+
def table_grid_tags
|
31
|
+
%i(start end top bottom insideH insideV)
|
32
|
+
end
|
33
|
+
|
34
|
+
def table_cell_margin_tags
|
35
|
+
%i(top start bottom end)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
ROWS = 4
|
40
|
+
CELLS = 4
|
41
|
+
|
42
|
+
document = OpenXml::Docx::Package.new
|
43
|
+
document.styles << default_table_style
|
44
|
+
|
45
|
+
include OpenXml::Docx::Elements
|
46
|
+
|
47
|
+
table = Table.new
|
48
|
+
table.table_style = "TableGrid"
|
49
|
+
|
50
|
+
ROWS.times do
|
51
|
+
row = TableRow.new
|
52
|
+
|
53
|
+
CELLS.times do
|
54
|
+
cell = TableCell.new
|
55
|
+
paragraph = Paragraph.new
|
56
|
+
cell << paragraph
|
57
|
+
row << cell
|
58
|
+
end
|
59
|
+
table << row
|
60
|
+
end
|
61
|
+
|
62
|
+
document.document << table
|
63
|
+
|
64
|
+
filename = "rocx_test_table.docx"
|
65
|
+
system "rm -f ~/Desktop/#{filename}" # -f so that we don't have an error if the file doesn't exist
|
66
|
+
document.save File.expand_path("~/Desktop/#{filename}")
|
67
|
+
exec "open ~/Desktop/#{filename}"
|
68
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Elements
|
4
|
+
class Table < Container
|
5
|
+
tag :tbl
|
6
|
+
|
7
|
+
value_property :bidi_visual, as: :bidi
|
8
|
+
value_property :cant_split
|
9
|
+
value_property :div_id
|
10
|
+
value_property :alignment
|
11
|
+
value_property :table_caption
|
12
|
+
value_property :table_description
|
13
|
+
value_property :table_layout
|
14
|
+
value_property :table_overlap
|
15
|
+
value_property :table_style
|
16
|
+
|
17
|
+
property :conditional_formatting
|
18
|
+
property :shading
|
19
|
+
property :table_borders
|
20
|
+
property :table_cell_margins
|
21
|
+
property :table_cell_spacing
|
22
|
+
property :table_indent
|
23
|
+
property :table_look
|
24
|
+
property :table_p_pr
|
25
|
+
property :table_width
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Elements
|
4
|
+
class TableCell < Container
|
5
|
+
tag :tc
|
6
|
+
|
7
|
+
attribute :id
|
8
|
+
|
9
|
+
value_property :div_id
|
10
|
+
value_property :grid_span
|
11
|
+
value_property :hide_mark
|
12
|
+
value_property :no_wrap
|
13
|
+
value_property :table_cell_fit_text
|
14
|
+
value_property :text_direction
|
15
|
+
|
16
|
+
property :conditional_formatting
|
17
|
+
property :headers
|
18
|
+
property :shading
|
19
|
+
property :table_cell_borders
|
20
|
+
property :table_cell_cell_margin
|
21
|
+
property :table_cell_width
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Elements
|
4
|
+
class TableRow < Container
|
5
|
+
tag :tr
|
6
|
+
|
7
|
+
attribute :rsidDel, expects: :valid_long_hex
|
8
|
+
attribute :rsidR, expects: :valid_long_hex
|
9
|
+
attribute :rsidRPr, expects: :valid_long_hex
|
10
|
+
attribute :risdTr, expects: :valid_long_hex
|
11
|
+
|
12
|
+
value_property :cant_split
|
13
|
+
value_property :div_id
|
14
|
+
value_property :grid_after
|
15
|
+
value_property :grid_before
|
16
|
+
value_property :hidden
|
17
|
+
value_property :alignment
|
18
|
+
value_property :table_header
|
19
|
+
value_property :v_align
|
20
|
+
|
21
|
+
property :conditional_formatting
|
22
|
+
property :table_cell_spacing
|
23
|
+
property :tr_height
|
24
|
+
property :w_after
|
25
|
+
property :w_before
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def valid_long_hex(value)
|
30
|
+
value =~ /^[0-9a-f]+$/i
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/openxml/docx/package.rb
CHANGED
@@ -23,6 +23,9 @@ module OpenXml
|
|
23
23
|
@styles = OpenXml::Docx::Parts::Styles.new
|
24
24
|
@document = OpenXml::Docx::Parts::Document.new
|
25
25
|
|
26
|
+
doc_rels.add_relationship REL_STYLES, "styles.xml"
|
27
|
+
doc_rels.add_relationship REL_SETTINGS, "settings.xml"
|
28
|
+
|
26
29
|
add_part "word/_rels/document.xml.rels", doc_rels
|
27
30
|
add_part "word/document.xml", document
|
28
31
|
add_part "word/settings.xml", settings
|
@@ -11,9 +11,11 @@ require "openxml/docx/properties/value_property"
|
|
11
11
|
require "openxml/docx/properties/boolean_property"
|
12
12
|
require "openxml/docx/properties/integer_property"
|
13
13
|
require "openxml/docx/properties/positive_integer_property"
|
14
|
+
require "openxml/docx/properties/string_property"
|
14
15
|
require "openxml/docx/properties/on_off_property"
|
15
16
|
require "openxml/docx/properties/toggle_property"
|
16
17
|
require "openxml/docx/properties/string_property"
|
18
|
+
require "openxml/docx/properties/width_property"
|
17
19
|
require "openxml/docx/properties/container_property"
|
18
20
|
require "openxml/docx/properties/style"
|
19
21
|
Dir.glob("#{File.join(File.dirname(__FILE__), "properties", "*.rb")}").each do |file|
|
@@ -6,6 +6,12 @@ module OpenXml
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
attr_reader :property_name
|
9
|
+
attr_reader :allowed_tags
|
10
|
+
|
11
|
+
def tag_is_one_of(tags)
|
12
|
+
attr_accessor :tag
|
13
|
+
@allowed_tags = tags
|
14
|
+
end
|
9
15
|
|
10
16
|
def tag(*args)
|
11
17
|
@tag = args.first if args.any?
|
@@ -18,6 +24,14 @@ module OpenXml
|
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
27
|
+
def initialize(tag=nil, *args)
|
28
|
+
return unless self.class.allowed_tags
|
29
|
+
unless self.class.allowed_tags.include?(tag)
|
30
|
+
raise ArgumentError, "Invalid tag name for #{name}: #{tag.inspect}. It should be one of #{self.class.allowed_tags.join(", ")}."
|
31
|
+
end
|
32
|
+
@tag = tag
|
33
|
+
end
|
34
|
+
|
21
35
|
def render?
|
22
36
|
!value.nil?
|
23
37
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Properties
|
4
|
+
class TableBorder < ComplexProperty
|
5
|
+
tag_is_one_of %i(top start bottom end insideH insideV)
|
6
|
+
|
7
|
+
attribute :color, expects: :hex_color
|
8
|
+
attribute :frame, expects: :true_or_false
|
9
|
+
attribute :shadow, expects: :true_or_false
|
10
|
+
attribute :space, expects: :positive_integer
|
11
|
+
attribute :theme_color, expects: :valid_theme_color
|
12
|
+
attribute :theme_shade, expects: :hex_digit
|
13
|
+
attribute :theme_tint, expects: :hex_digit
|
14
|
+
attribute :value, expects: :valid_type, displays_as: :val
|
15
|
+
attribute :width, expects: :positive_integer, displays_as: :sz
|
16
|
+
|
17
|
+
def initialize(tag, value)
|
18
|
+
super tag
|
19
|
+
@value = value
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module OpenXml
|
2
|
+
module Docx
|
3
|
+
module Properties
|
4
|
+
class TableCellBorder < ComplexProperty
|
5
|
+
tag_is_one_of %i(top start bottom end insideH insideV tl2br tr2bl)
|
6
|
+
|
7
|
+
attribute :color, expects: :hex_color
|
8
|
+
attribute :frame, expects: :true_or_false
|
9
|
+
attribute :shadow, expects: :true_or_false
|
10
|
+
attribute :space, expects: :positive_integer
|
11
|
+
attribute :theme_color, expects: :valid_theme_color
|
12
|
+
attribute :theme_shade, expects: :hex_digit
|
13
|
+
attribute :theme_tint, expects: :hex_digit
|
14
|
+
attribute :value, expects: :valid_type, displays_as: :val
|
15
|
+
attribute :width, expects: :positive_integer, displays_as: :sz
|
16
|
+
|
17
|
+
def initialize(tag, value)
|
18
|
+
super tag
|
19
|
+
self.value = value
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|