<img src=“https://travis-ci.org/jawspeak/ruby-docx-templater.png” />
Inspired from [github.com/jawspeak/ruby-docx-templater] and [github.com/michaelfranzl/docx_converter], this takes a .docx file and uses it as a template to create a new docx, with your data
-
All manipulation in memory (great if you have sensitive data)
-
Global key/value substitutions by entering a ‘$KEY$` anywhere in the word document, with whatever formatting you want.
-
Multi-row loops inside tables, also with whatever your formatting you wish. ‘#BEGIN_ROW:XYZ#`… `#END_ROW:XYZ#` see tests/example
-
Allows for embedded loops through fully recursive parsing of the document
-
Create your docx “template” in Word
-
Install rvm and bundler
-
Run ‘bundle install`.
-
Render new docx files from the template, ex: ‘ruby render_docx_template.rb`. Look for a rendered_*.docx file.
-
Sample output with tests: ‘rake spec` (unit tests) `rake integration` (opens word)
__MS WORD is painful__ You will probably need to modify your docx document in word until such a time as all flags to replace are set properly within a single XML element. You can’t have Word’s split a string of characters across multiple xml elements in your template document. Test the template and keep fixing it until the fields are all set properly.
I frequently use this workflow:
- Cut string to replace out to notepad - Paste string back into MS Word - Save Word Document