docx 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +27 -3
- data/lib/docx/document.rb +3 -0
- data/lib/docx/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 16df363293a0fcb4945e4ab7aa968f7138f2d0e38d25bcf689a5c5142279e520
|
|
4
|
+
data.tar.gz: '089d8ef9c78a7ae13d980d3a78ce729b05fe6dff1fefe8bbdfe4488a6b7b0f91'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8a23b154632578c3a702d3e16b6bbc3d763f062860ea9cf8db6c6814e89c1e7d99073fa28b7f90276c883d5c1f47be9d688d6f05177c06dbfc3bc452ccadc371
|
|
7
|
+
data.tar.gz: a8a735936caad5c75f56cace55e980df01bb25af795d5b8d040b735b14510898b220da3b8f40c52b74c68dc371c9a2d25bc2791d44a54a74dde9db727d3432ae
|
data/README.md
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
[](https://coveralls.io/github/ruby-docx/docx?branch=master)
|
|
6
6
|
[](https://gitter.im/ruby-docx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
|
7
7
|
|
|
8
|
-
A ruby library/gem for interacting with `.docx` files. currently capabilities include reading paragraphs/bookmarks, inserting text at bookmarks, reading tables/rows/columns/cells and saving the document.
|
|
8
|
+
A ruby library/gem for interacting with `.docx` files. currently capabilities include reading paragraphs/bookmarks, inserting text at bookmarks, reading and writing headers/footers, reading tables/rows/columns/cells and saving the document.
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
12
12
|
### Prerequisites
|
|
13
13
|
|
|
14
|
-
- Ruby 2.
|
|
14
|
+
- Ruby 2.7 or later
|
|
15
15
|
|
|
16
16
|
### Install
|
|
17
17
|
|
|
@@ -63,6 +63,26 @@ doc = Docx::Document.open(buffer)
|
|
|
63
63
|
# Everything about reading is the same as shown above
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
### Reading headers and footers
|
|
67
|
+
|
|
68
|
+
``` ruby
|
|
69
|
+
require 'docx'
|
|
70
|
+
|
|
71
|
+
doc = Docx::Document.open('example.docx')
|
|
72
|
+
|
|
73
|
+
# Headers and footers are returned as hashes keyed by their file name
|
|
74
|
+
# (e.g. "header1", "footer1"), with Nokogiri documents as values.
|
|
75
|
+
doc.headers.each do |name, header|
|
|
76
|
+
puts name
|
|
77
|
+
puts header.text
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
doc.footers.each do |name, footer|
|
|
81
|
+
puts name
|
|
82
|
+
puts footer.text
|
|
83
|
+
end
|
|
84
|
+
```
|
|
85
|
+
|
|
66
86
|
### Rendering html
|
|
67
87
|
``` ruby
|
|
68
88
|
require 'docx'
|
|
@@ -116,7 +136,11 @@ doc = Docx::Document.open('example.docx')
|
|
|
116
136
|
doc.bookmarks['example_bookmark'].insert_text_after("Hello world.")
|
|
117
137
|
|
|
118
138
|
# Insert multiple lines of text at our bookmark
|
|
119
|
-
doc.bookmarks['example_bookmark_2'].
|
|
139
|
+
doc.bookmarks['example_bookmark_2'].insert_multiple_lines(['Hello', 'World', 'foo'])
|
|
140
|
+
|
|
141
|
+
# Bookmarks placed in headers and footers are included too, and edits to them
|
|
142
|
+
# are saved along with the document.
|
|
143
|
+
doc.bookmarks['header_bookmark'].insert_text_after("Hello from the header.")
|
|
120
144
|
|
|
121
145
|
# Remove paragraphs
|
|
122
146
|
doc.paragraphs.each do |p|
|
data/lib/docx/document.rb
CHANGED
|
@@ -70,6 +70,9 @@ module Docx
|
|
|
70
70
|
def bookmarks
|
|
71
71
|
bkmrks_hsh = {}
|
|
72
72
|
bkmrks_ary = @doc.xpath('//w:bookmarkStart').map { |b_node| parse_bookmark_from b_node }
|
|
73
|
+
# also scan headers and footers so their bookmarks can be read and edited
|
|
74
|
+
bkmrks_ary += headers.values.flat_map { |h| h.xpath('//w:bookmarkStart').map { |b_node| parse_bookmark_from b_node } }
|
|
75
|
+
bkmrks_ary += footers.values.flat_map { |f| f.xpath('//w:bookmarkStart').map { |b_node| parse_bookmark_from b_node } }
|
|
73
76
|
# auto-generated by office 2010
|
|
74
77
|
bkmrks_ary.reject! { |b| b.name == '_GoBack' }
|
|
75
78
|
bkmrks_ary.each { |b| bkmrks_hsh[b.name] = b }
|
data/lib/docx/version.rb
CHANGED