NOTE: This pack uses the docxtemplater library to implement the tag replacement. For additional info + examples on building templates, see their . Types of Tags
1. Placeholders
Usage in Template Doc
GenerateWordDoc( ) Usage
GenerateWordDoc(template.docx, "My Document", "tagName", [string])
where [string] is any text value
GenerateDocFromJSON( ) Usage
GenerateDocFromJSON(template.docx, "My Document", "{"tagName":"[value]"}")
where [value] is any text value
2. Conditionals
Usage in Template Doc
{#tagName}Show this sentence.{/tagName}
GenerateWordDoc( ) Usage
GenerateWordDoc(template.docx, "My Document", "tagName", [boolean])
where [boolean] is either true() or false()
GenerateDocFromJSON( ) Usage
GenerateDocFromJSON(template.docx, "My Document", "{"tagName":[boolean]}")
where [boolean] is either true or false
3. Loops
Usage in Template Doc
{#loopTag}
Inner loop text. {innerLoopVariable}
{/loopTag}
GenerateWordDoc( ) Usage
N/A (can’t be used for loops)
GenerateDocFromJSON( ) Usage
GenerateDocFromJSON(template.docx, "My Document", "{"loopTag":[{"innerLoopVariable": "[value1]"}, {"innerLoopVariable": "[value2]"}, {"innerLoopVariable": "[value3]"}]}")
where [value1], [value2], and [value3] are any text values
Examples
1. Without Loops
Template Doc
Below is a template doc that uses one placeholder tag (name) and one conditional tag (showPara).
Input Data
The data we want to use in this template is below:
Button Formula
We will use the GenerateWordDoc formula since we don’t need loops. The button setup should look like this:
Try It!
Click the “Generate Word Doc” button to generate the filled-in word doc and then click the Download Link to save and view it. Try changing the values in the table to see how the exported Word Docs change. Download Link (expires after 15min)
2. With Loops
Template Doc
Input Data
Button Formula
We will use the GenerateDocFromJSON formula since we need loops this time. There are a few ways to generate JSON in Coda. Whichever method you use, you will need to end up with a JSON string that looks like this for the template doc and input data above:
{"name":"Sandy","showPara":true,"veggieList":[{"vegetable":"Carrots"},{"vegetable":"Cucumber"},{"vegetable":"Tomatoes"}]}
For this example, we’ve used the JSONify() and ListToText() formulas that are supplied in the Export to Word Pro pack to build the JSON. The complete formula looks like this:
The button setup for using the GenerateDocFromJSON() formula should look like this:
Try It!
Click the “Generate Word Doc” button to generate the filled-in word doc and then click the Download Link to save and view it. Try changing the values in the table to see how the JSON and the exported Word Docs change. Download Link (expires after 15min)