Sample

Replace contents in templates.

Blog Figure
A document with some replaced variables.

Templates

Placeholders meant to be replaced and other template options such as delete existing placeholders or limiting the number of replacements are defined with JSON.

You can find everything about replacing contents in templates. in the documentation.

This example replaces table and text placeholders and creates a new document without modifying the template that was used.

{
    "template": {
        "replace_tables": [
            {
                "placeholders": [
                    [
                        "NAME",
                        "STREET",
                        "PHONE",
                        "EMAIL",
                        "MOBILE"
                    ],
                    [
                        "PRODUCT",
                        "DESC",
                        "CODE",
                        "QUANTITY"
                    ]
                ],
                "values": [
                    [
                        [
                            "John",
                            "Mary",
                            "Tom"
                        ],
                        [
                            "Street 1,2B",
                            "Avenue 89",
                            "Street 6T"
                        ],
                        [
                            "+00 1002",
                            "03 2112",
                            "+00 122 1002"
                        ],
                        [
                            "john@mail.com",
                            "mary@mail.com",
                            "tom@mail.com"
                        ],
                        [
                            "61002",
                            "62112",
                            "61221002"
                        ]
                    ],
                    [
                        [
                            "Product A",
                            "Product B"
                        ],
                        [
                            "Desc product A",
                            "Desc product B"
                        ],
                        [
                            "Code A",
                            "Code B"
                        ],
                        [
                            "110",
                            "200"
                        ]
                    ]
                ]
            }
        ],
        "replace_texts": [
            {
                "placeholders": [
                    "TOTAL"
                ],
                "values": [
                    "310"
                ]
            }
        ]
    }
}

The command to execute in order to replace variables in a template is:

dynadocx -d data.json -t template.docx
Blog Figure
A document with some replaced variables.
Icon