Docx handler
Handles reading, populating, and saving .docx files using the python-docx library. Use this skill for any tasks involving template filling or modifying Word documents.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill docx-handlerAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.5 KB, 285 tokens by cl100k_base, as published. Nobody here has run it
DOCX Handler
Use this skill when you need to manipulate .docx files.
Basic Workflow
- Load document:
doc = Document('path/to/template.docx') - Iterate paragraphs/tables and replace placeholder text.
- Save document:
doc.save('path/to/output.docx')
Handling Placeholders
Use a simple text replacement for paragraphs and tables:
from docx import Document
def replace_text(doc, old_text, new_text):
for paragraph in doc.paragraphs:
if old_text in paragraph.text:
paragraph.text = paragraph.text.replace(old_text, new_text)
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
for paragraph in cell.paragraphs:
if old_text in paragraph.text:
paragraph.text = paragraph.text.replace(old_text, new_text)
doc = Document('template.docx')
replace_text(doc, '{{NAME}}', 'John Doe')
doc.save('output.docx')
Handling Conditional Blocks
For conditional sections (e.g., {{IF_TAG}}...{{END_IF_TAG}}):
- Identify the paragraph(s) containing the opening and closing tags.
- If condition is true: remove tags, keep content.
- If condition is false: remove paragraph(s) containing the tags and everything between them.
What ships with it: 1 file
3.9 KB alongside SKILL.md, 1 of them executable
scripts/
- quick_validate.pyruns3.9 KB