DOCX Generator
When to Use This Skill
Use this skill when:
- Creating Word documents programmatically from data or specifications
- Populating branded templates with dynamic content while preserving corporate styling
- Extracting text, tables, and structure from existing DOCX files for analysis
- Finding and replacing placeholder text like
{{TITLE}}or${author} - Automating document generation workflows (reports, contracts, letters)
Do NOT use this skill when:
- User wants to open/view documents (use native Word or viewer)
- Complex mail merge with data sources (use native Word mail merge)
- Working with older .doc format (DOCX only)
- PDF output is needed (use pdf-generator skill instead)
Prerequisites
- Deno installed (https://deno.land/)
- Input DOCX files for template-based operations
- JSON specification for scratch generation
Quick Start
Two Modes of Operation
-
Template Mode: Modify existing branded templates
- Analyze template to find placeholders
- Replace
{{PLACEHOLDERS}}with actual content
-
Scratch Mode: Create documents from nothing using JSON specifications
Instructions
Mode 1: Template-Based Generation
Step 1a: Analyze the Template
Extract text inventory to understand what can be replaced:
Output (inventory.json):
Step 1b: Create Replacement Specification
Create replacements.json:
Step 1c: Generate Output
Mode 2: From-Scratch Generation
Step 2a: Create Specification
Create spec.json:
Step 2b: Generate Document
Examples
Example 1: Contract Generation
Scenario: Generate contracts from a branded template.
Steps:
Example 2: Report with Tables
Scenario: Generate a data report with tables and formatting.
spec.json:
Example 3: Letter with Headers/Footers
Scenario: Create a formal letter with letterhead.
spec.json:
Script Reference
Specification Reference
Paragraph Options
Text Run Options
Table Options
Hyperlink Options
Common Issues and Solutions
Issue: Placeholders not being replaced
Symptoms: Output DOCX still contains {{PLACEHOLDER}} tags.
Solution:
- Run
analyze-template.tsto verify exact tag text - Tags may be split across XML runs - the script consolidates these automatically
- Ensure
includeHeadersandincludeFootersare true if placeholders are there
Issue: Formatting lost after replacement
Symptoms: Replaced text doesn't match original formatting.
Solution:
- Text replacement preserves the formatting of the original placeholder
- Ensure placeholder is formatted the way you want the final text to appear
Issue: Images not appearing
Symptoms: Image elements are blank in output.
Solution:
- Use paths relative to the spec.json file location
- Verify image file exists and is readable
- Check supported formats: PNG, JPEG, GIF
Issue: Table cell content incorrect
Symptoms: Table cells have wrong content or formatting.
Solution:
- Each cell's
contentmust be an array of paragraph specifications - Use
shadingfor background color,verticalAlignfor alignment
Limitations
- DOCX only: Does not support legacy .doc format
- No track changes: Cannot add or process track changes
- No comments: Cannot add document comments
- No macros: Cannot include VBA macros
- Basic numbering: Limited support for complex numbering schemes
- Text run splitting: Word may split text across XML elements; script handles common cases
Related Skills
- pptx-generator: For creating PowerPoint presentations
- xlsx-generator: For creating Excel spreadsheets
- pdf-generator: For creating PDF documents

