Skip to content

A Ruby library to template Microsoft Word .docx files. Generates new Word .docx files based on a template file. Does templating entirely in memory.

License

Notifications You must be signed in to change notification settings

pl0o0f/docx-templater

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<img src=“https://travis-ci.org/jawspeak/ruby-docx-templater.png” />

Turns a docx file template and a data set into a fully formed docx document

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

Features

  • 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

Usage

  • 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

About

A Ruby library to template Microsoft Word .docx files. Generates new Word .docx files based on a template file. Does templating entirely in memory.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%