用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill python-docx-templating命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
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.
Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.
This skill includes search capability in 13F, such as fuzzy search a fund information using possibly inaccurate name, or fuzzy search a stock cusip info using its name.
基于 SOC 职业分类
正在显示 SKILL.md
| name | python-docx-templating |
| description | A skill for replacing placeholders and handling conditional blocks in python-docx. |
This skill covers how to read a Word document template, replace {{VAR}} style placeholders with actual values, and conditionally remove or keep sections of text based on {{IF_COND}}...{{END_IF_COND}} logic.
Ensure python-docx is installed:
pip install python-docx
When replacing placeholders, be mindful that python-docx splits paragraph text into multiple Run objects. For simple documents where inline formatting (bold, italic) inside the placeholder itself doesn't matter, you can replace paragraph.text directly, which will clear run-level formatting but keep paragraph-level styling. If run-level formatting is critical, use a regex or custom run-merging logic.
import docx
doc = docx.Document('template.docx')
context = {'NAME': 'John Doe', 'COMPANY': 'Acme Corp'}
for paragraph in doc.paragraphs:
for key, value in context.items():
placeholder = f"{{{{{key}}}}}"
if placeholder in paragraph.text:
paragraph.text = paragraph.text.replace(placeholder, str(value))
doc.save('output.docx')
To handle conditional blocks like {{IF_RELOCATION}} ... {{END_IF_RELOCATION}}:
import re
def process_conditionals(text, condition_true):
if condition_true:
# Keep content, remove tags
text = re.sub(r'\{\{IF_RELOCATION\}\}(.*?)\{\{END_IF_RELOCATION\}\}', r'\1', text, flags=re.DOTALL)
else:
# Remove entire block including tags
text = re.sub(r'\{\{IF_RELOCATION\}\}.*?\{\{END_IF_RELOCATION\}\}', '', text, flags=re.DOTALL)
return text
This regex approach can be applied to paragraph.text to correctly render the conditional.