docx

Replace placeholders across runs, tables, headers, and footers in Word documents.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/3172973615/skill-explore --skill docx-3172973615
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docx
Source: https://github.com/3172973615/skill-explore/tree/main/skillsbench_subset/tasks/offer-letter-generator/environment/skills/docx
Command: npx skills add https://github.com/3172973615/skill-explore --skill docx-3172973615

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Word documents frequently store placeholders across separate XML runs, which can break naive replacements. This Skill provides robust techniques to detect and replace placeholders that may be split across runs, tables, headers, and footers.

Core Features & Use Cases

  • Robust, run-agnostic placeholder replacement across paragraphs, tables (including nested tables), headers, and footers.
  • Handles common patterns like {{KEY}} and preserves original formatting by rebuilding runs without losing styles.
  • Practical use: generate personalized letters or templates that must maintain styling while injecting data.

Quick Start

Fill a Word template with data from a source and save the filled document.

Frequently Asked Questions about docx

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace placeholders in a Word document when they are split across runs?

Replacing placeholders in a Word document that are split across runs requires a run-agnostic approach that detects and rebuilds the fragmented XML structures. This technique ensures replacements occur accurately across paragraphs, tables, headers, and footers.

Why does my python-docx template replacement fail to find placeholders in headers and footers?

Template replacement in python-docx often fails in headers and footers because naive text searches do not account for placeholders split across separate XML runs. A robust replacement technique must scan and rebuild these runs to successfully inject data.

Can I generate Word documents from a data source while preserving the original template formatting?

Generating Word documents from a data source while preserving template formatting is possible by rebuilding runs without losing styles during replacement. This allows personalized letters and reports to maintain original styling across paragraphs and nested tables.

What is the best way to automate contract assembly using Word templates and python-docx?

Automating contract assembly using Word templates and python-docx is best handled by a robust replacement mechanism that maps a data source to placeholders. This approach preserves formatting by accurately replacing values split across runs, tables, headers, and footers.

Does python-docx support replacing text inside nested tables without breaking the template layout?

python-docx supports replacing text inside nested tables without breaking the layout when using a run-agnostic replacement method. This technique detects placeholders split across table cells and rebuilds the runs while preserving the original formatting and styles.

What data source format do I need to map placeholders to values for Word document generation?

To map placeholders to values for Word document generation, you need a data source that pairs template keys with replacement values. This mapping is required by the python-docx library to perform automated placeholder replacements across the document.