docx-template-fill
/docx-template-fill
Wypełnia szablony Word (.docx) z symbolami zastępczymi typu {{PLACEHOLDER}}, obsługuje symbole rozbite na kilka fragmentów XML i sekcje warunkowe, zachowując formatowanie.
- Autor
- cxcscmu ↗
- Repozytorium
- SkillLearnBench ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 02.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 02.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Wypełnia szablony Word (.docx) z symbolami zastępczymi typu {{PLACEHOLDER}}, obsługuje symbole rozbite na kilka fragmentów XML i sekcje warunkowe, zachowując formatowanie.
Oryginalny opis (EN)
Fill Word document (.docx) templates that use placeholder syntax like {{PLACEHOLDER}}. Handles split placeholders (where Word splits a placeholder across multiple XML runs), conditional sections ({{IF_X}}...{{END_IF_X}}), and preserves formatting. Use this skill whenever the user asks to fill a Word template, generate a document from a template, or replace placeholders in a .docx file.
Jak działa
- Core Challenge: Split Placeholders
- Strategy
- Implementation Pattern
- Workflow
Podgląd SKILL.md
---
name: docx-template-fill
description: >
Fill Word document (.docx) templates that use placeholder syntax like {{PLACEHOLDER}}.
Handles split placeholders (where Word splits a placeholder across multiple XML runs),
conditional sections ({{IF_X}}...{{END_IF_X}}), and preserves formatting.
Use this skill whenever the user asks to fill a Word template, generate a document
from a template, or replace placeholders in a .docx file.
---
# DOCX Template Fill
## Core Challenge: Split Placeholders
Word internally splits text into "runs" based on formatting changes, spell-check boundaries,
or editing history. A placeholder like `{{COMPANY_NAME}}` may become three runs:
`{{COMP` + `ANY_` + `NAME}}`. Naive per-run replacement will fail.
## Strategy
1. **Merge-then-replace at the run level**: For each paragraph (and header/footer/table cell
paragraph), concatenate all run texts, perform regex replacements on the merged string,
then redistribute text back to runs — putting all text in the first run and clearing the rest.
This preserves the first run's formatting.
2. **Process all text containers**: Paragraphs live in the document body, but also in:
- Table cells (iterate `doc.tables[*].rows[*].cells[*].paragraphs`)
- Section headers (`doc.sections[*].header.paragraphs`)
- Section footers (`doc.sections[*].footer.paragraphs`)
3. **Conditional sections**: For `{{IF_KEY}}...content...{{END_IF_KEY}}`:
- If condition is true (value is "Yes"), remove only the markers, keep content
- If condition is false, remove markers and all content between them
- Conditionals may span a single paragraph or the markers may be in separate runs
## Implementation Pattern
```python
import re, json
from docx import Document
def replace_in_paragraph(paragraph, replacements):
"""Replace placeholders in a paragraph, handling split runs."""
full_text = "".join(run.text for run in paragraph.runs)
if not full_text:
return
new_text = full_text
for key, value in replacements.items():
new_text = new_text.replace("{{" + key + "}}", value)
if new_text != full_text:
# Put all text in first run, clear the rest (preserves first run's formatting)
for i, run in enumerate(paragraph.runs):
if i == 0:
run.text = new_text
else:
run.text = ""
def handle_conditional(paragraph, key, keep):
"""Handle {{IF_key}}...{{END_IF_key}} within a single paragraph."""
full_text = "".join(run.text for run in paragraph.runs)
pattern = r"\{\{IF_" + key + r"\}\}(.*?)\{\{END_IF_" + key + r"\}\}"
if re.search(pattern, full_text):
if keep:
new_text = re.sub(pattern, r"\1", full_text)
else:
new_text = re.sub(pattern, "", full_text)
for i, run in enumerate(paragraph.runs):
run.text = new_text if i == 0 else ""
def process_all_paragraphs(doc, func, *args):
"""Apply a function to every paragraph in the document."""
for p in doc.paragraphs:
func(p, *args)
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
for p in cell.paragraphs:
func(p, *args)
for section in doc.sections:
for p in section.header.paragraphs:
func(p, *args)
for p in section.footer.paragraphs:
func(p, *args)
```
## Workflow
1. Load data (JSON) and template (docx)
2. Handle conditionals first (before placeholder replacement)
3. Replace all `{{KEY}}` placeholders with values from data
4. Save the filled document
Wersje
W bazie nie ma innych skilli o nazwie docx-template-fill.
Migawka bazy z 13.11.2026 · wersja paczki bd67c5f6c5e2 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 2 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100word-placeholder-replacement
Zastępuje znaczniki {{PLACEHOLDER}} w szablonach Word (.docx) i obsługuje sekcje warunkowe typu {{IF_CONDITION}}...{{END_IF_CONDITION}}. - 100docx-template-filling
Wypełnia szablony Word (.docx) danymi z JSON, obsługując rozbite symbole zastępcze, zagnieżdżone tabele, nagłówki i stopki oraz logikę warunkową IF i END_IF. - 90document-generation
Planuje zmiany w szablonach Word do generowania dokumentów w Dataverse: mapuje pola, kontrolki treści i symbole zastępcze. - 93fill-docx-template
Wypełnia szablony Word (.docx) danymi: zastępuje placeholdery, wypełnia tabele według znaczników, wstawia obrazy i generuje dokumenty seryjnie, na przykład raporty i umowy. - 90docx-authoring
Generuje i edytuje dokumenty Word .docx: tworzenie, wypełnianie szablonu i edycja XML treści przez bibliotekę, z walidacją w obie strony. - 95Docx
Przetwarza dokumenty Word (.docx), czyli tworzy, odczytuje i poprawia pliki Worda.