Run1 docx template manipulation
Strategies for programmatically modifying .docx files, handling placeholders, and performing conditional text removal.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill run1_docx-template-manipulationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.2 KB, 248 tokens by cl100k_base, as published. Nobody here has run it
Handling Template Placeholders
Since the source is a .docx file, standard text replacement is not possible because Word files are zipped XML structures.
- Library Selection: Use the
python-docxordocxtpllibrary to interact with the file structure.docxtplis recommended as it natively supports Jinja2-style syntax ({{VAR}}). - Standard Replacement: Iterate through the document's paragraphs and tables to swap placeholders like
{{CANDIDATE_FULL_NAME}}with the corresponding value from the JSON data.
Conditional Content Logic
To handle the {{IF_RELOCATION}} blocks:
- Evaluation: Check the
RELOCATION_PACKAGEboolean or string from the JSON data. - Processing:
- If "Yes": Remove the
{{IF_RELOCATION}}and{{END_IF_RELOCATION}}markers while keeping the text contained between them. - If "No" (or empty): Remove the entire block, including the markers and the text contained within them.
- If "Yes": Remove the
- Save: Once modifications are complete, save the object as
/root/offer_letter_filled.docx.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.