You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
4
8
5
9
## Usage
6
10
11
+
### Prerequisites
12
+
13
+
- Ruby 2.4 or later
14
+
7
15
### Install
8
16
9
-
Requires ruby (tested with 2.1.1)
17
+
Add the following line to your application's Gemfile:
10
18
11
-
gem 'docx', '~> 0.2.07', :require => ["docx"]
19
+
```ruby
20
+
gem 'docx'
21
+
```
22
+
23
+
And then execute:
24
+
25
+
```shell
26
+
bundle install
27
+
```
28
+
29
+
Or install it yourself as:
30
+
31
+
```shell
32
+
gem install docx
33
+
```
12
34
13
35
### Reading
14
36
@@ -29,6 +51,17 @@ doc.bookmarks.each_pair do |bookmark_name, bookmark_object|
29
51
end
30
52
```
31
53
54
+
Don't have a local file but a buffer? Docx handles those to:
55
+
56
+
```ruby
57
+
require'docx'
58
+
59
+
# Create a Docx::Document object from a remote file
60
+
doc =Docx::Document.open(buffer)
61
+
62
+
# Everything about reading is the same as shown above
63
+
```
64
+
32
65
### Rendering html
33
66
```ruby
34
67
require'docx'
@@ -61,7 +94,7 @@ doc.tables.each do |table|
61
94
puts cell.text
62
95
end
63
96
end
64
-
97
+
65
98
table.columns.each do |column| # Column-based iteration
# This stores the current global document properties, for now
38
46
defdocument_properties
@@ -41,25 +49,24 @@ def document_properties
41
49
}
42
50
end
43
51
44
-
45
52
# With no associated block, Docx::Document.open is a synonym for Docx::Document.new. If the optional code block is given, it will be passed the opened +docx+ file as an argument and the Docx::Document oject will automatically be closed when the block terminates. The values of the block will be returned from Docx::Document.open.
0 commit comments