How to edit docx templates word document court report - rubyforgood/casa GitHub Wiki

Table of Contents generated with DocToc

Word document templates are handled by the gem sablon
Sablon looks for mergefields in word documents for instructions.

To make a mergefield go to insert>quick parts>field. This is in microsoft office 2007. I'm sure later versions have something similar. mergefield location

Then this window pops up. Select "Mergefield" then click "Field Codes".
field menu

Sablon instructions go in this text box
code text field

To access mergefields easier, fields can be added to the quick access toolbar by right clicking it.
right click menu
and it will appear in the menu top left
top left menu

❗❗❗Heads Up❗❗❗

Editing merge field text surrounded by <<>> does not change the instruction in the mergefield
It is possible to have an invisible mergefield containing no text at all
default mergeview look
To toggle seeing actual mergefields text press alt + f9
toggled mergeview look

Also
Sometimes syntax errors aren't detected by sablon and the document generated from the template comes out incorrectly. It's best to only add 1 or 2 instructions at a time then test.

Environment

Microsoft Office 2007 is the earliest version supporting .docx files

Previous work:

  1. https://github.com/rubyforgood/casa/issues/2265
  2. https://github.com/rubyforgood/casa/pull/1942
  3. https://github.com/rubyforgood/casa/issues/1826