docxtemplater Documentation

repository·master·Indexed 25 days ago

https://github.com/open-xml-templating/docxtemplater

A library for generating .docx, .pptx, and .xlsx documents from templates by replacing placeholders with JSON data. Supports loops, conditions, and custom XML insertion. Compatible with Node.js, the browser, and the command line. Includes optional modules for images, HTML insertion, charts, and advanced styling.

Tokens
462
Snippets
0
Records
3
Agent score
36%

What's inside docxtemplater

  1. Overview of docxtemplater

    master
    docxtemplater is a library used to generate .docx or .pptx documents from existing template files. It allows you to replace {placeholders} with data from a JSON object and supports advanced templating features like loops, conditions, and custom XML insertion. Templates are designed to be editable by non-programmers (e.g., clients) directly in Microsoft Word or PowerPoint.
  2. Core templating features of docxtemplater

    master

    The core library supports several templating syntaxes:

    • Simple Replacement: Replace {placeholder} with a value.
    • Loops: Use {#users} {name} {/users} to iterate over arrays.
    • Table Loops: Use loops within tables to generate dynamic columns or rows.
    • Conditions: Use angular-style parsing for logic, e.g., {#users.length > 3}.
    • XML Insertion: Insert custom XML using {@rawXml} to include pre-formatted text.
  3. Available docxtemplater modules

    master

    Functionality can be extended using various paid modules. Key modules include:

    • Image module: Add images using {%image}.
    • Html Module: Insert formatted text in .docx using {~html}.
    • XLSX Module: Perform templating on Excel files (.xlsx).
    • Chart Module: Replace charts using {$chart}.
    • Html-Pptx Module: Insert formatted text in .pptx using {~html}.
    • Slides Module: Create multiple slides dynamically using {:users}.
    • Subtemplate Module: Include external .docx files using {:include doc}.
    • Subsection Module: Include headers/footers from another document using {:subsection doc}.
    • Word-Run Module: Include raw runs (<w:r>) using {r@wrun}.
    • QrCode Module: Replace an image with a QR code while keeping existing properties.
    • Table Module: Create tables from 2D data using {:table data}.
    • Styling Module: Restyle paragraphs, cells, or tables using {:stylepar style}.
    • Paragraph Placeholder Module: Show/hide paragraphs using {?tag}.