agentleFS
phanghonghaophanghonghao/THU-Awesome-Skills/skills/assignment-word/SKILL.md

assignment-word

Skill8 starsChanged 3 months agoMITView on GitHub

Edit and fill Word (.docx) documents — inspect structure, replace text, batch fill placeholders, insert images, and fill tables. Use when user mentions "assignment-word", "docx_editor", "填Word", "填docx", "Word填写", "replace docx", "fill docx", or needs to programmatically modify a Word document.

  • Installs packages

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 0 are distinctive, and 10 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    After converting PDF to Word with pdf2word, need to fill in content

    line 14
  2. Very specific:

    Use info to inspect document structure and find placeholder text

    line 74
  3. Very specific:

    Use replace for simple text substitutions

    line 75
  4. Very specific:

    Use fill for batch replacements from a JSON file

    line 76
  5. Very specific:

    Use image to insert images at specific locations

    line 77
  6. Very specific:

    Use table to fill specific table cells with data

    line 78
  7. Very specific:

    Always use PYTHONIOENCODING=utf-8 on Windows

    line 82
  8. Very specific:

    Default behavior is in-place edit with .bak backup

    line 83
  9. Very specific:

    Use -o to save to a new file instead of modifying the original

    line 84
  10. Very specific:

    Chinese font fix: Always use set_run_font(run) instead of run.font.name = '宋体' — python-docx's font.name only sets Western fonts …

    line 87

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Assignment Word Editor (docx_editor.py)

Programmatically edit Word (.docx) documents using python-docx. Supports text replacement (preserving formatting), batch placeholder filling, image insertion, and table data filling.

When to Use

  • User mentions: "assignment-word", "docx_editor", "填Word", "填docx", "Word填写", "replace docx"
  • Need to inspect, fill, or modify a Word document programmatically
  • After converting PDF to Word with pdf2word, need to fill in content

Dependencies

python -m pip install python-docx 2>&1 | tail -3

Commands

info — Print document structure

Prints paragraphs, tables, headers/footers with index numbers for targeting edits.

PYTHONIOENCODING=utf-8 python "<LOCAL_USER>/.claude/skills/assignment-word/docx_editor.py" info "<docx_path>"

replace — Find and replace text (preserving formatting)

PYTHONIOENCODING=utf-8 python "<LOCAL_USER>/.claude/skills/assignment-word/docx_editor.py" replace "<docx_path>" --old "OLD_TEXT" --new "NEW_TEXT" [-o output.docx]

fill — Batch replace placeholders from JSON

JSON format: { "placeholder1": "value1", "placeholder2": "value2" }

PYTHONIOENCODING=utf-8 python "<LOCAL_USER>/.claude/skills/assignment-word/docx_editor.py" fill "<docx_path>" --data replacements.json [-o output.docx]

image — Insert image after matching text

PYTHONIOENCODING=utf-8 python "<LOCAL_USER>/.claude/skills/assignment-word/docx_editor.py" image "<docx_path>" --after "图1" --img "figure.png" [-o output.docx]

table — Fill table data from JSON

JSON format: { "cells": { "0,0": "value", "1,2": "value" } } (row,col → value)

PYTHONIOENCODING=utf-8 python "<LOCAL_USER>/.claude/skills/assignment-word/docx_editor.py" table "<docx_path>" --idx 0 --data table_data.json [-o output.docx]

Arguments

ArgumentDescription
-o, --outputOutput file path. Default: in-place edit (original backed up as .bak)
--oldOld text to find (for replace)
--newNew replacement text (for replace)
--dataPath to JSON data file (for fill and table)
--afterText to search for, image inserted after this paragraph (for image)
--imgImage file path to insert (for image)
--idxTable index (0-based, for table)

Workflow

  1. Use info to inspect document structure and find placeholder text
  2. Use replace for simple text substitutions
  3. Use fill for batch replacements from a JSON file
  4. Use image to insert images at specific locations
  5. Use table to fill specific table cells with data

Rules

  1. Always use PYTHONIOENCODING=utf-8 on Windows
  2. Default behavior is in-place edit with .bak backup
  3. Use -o to save to a new file instead of modifying the original
  4. Text replacement preserves original run formatting (bold, italic, font, size)
  5. For fill, placeholders like {{姓名}} will be matched and replaced
  6. Chinese font fix: Always use set_run_font(run) instead of run.font.name = '宋体' — python-docx's font.name only sets Western fonts (ascii/hAnsi), NOT East Asian (w:eastAsia). Without setting eastAsia, Chinese characters render in Word's default font causing garbled text

Chinese Font Fix (Critical)

python-docx's run.font.name = '宋体' only sets w:ascii and w:hAnsi attributes. Chinese characters use w:eastAsia which must be set via XML:

from docx.oxml.ns import qn
from docx.oxml import OxmlElement

def set_run_font(run, font_name='宋体'):
    run.font.name = font_name
    rPr = run._element.get_or_add_rPr()
    rFonts = rPr.find(qn('w:rFonts'))
    if rFonts is None:
        rFonts = OxmlElement('w:rFonts')
        rPr.insert(0, rFonts)
    rFonts.set(qn('w:eastAsia'), font_name)
    rFonts.set(qn('w:ascii'), font_name)
    rFonts.set(qn('w:hAnsi'), font_name)

This applies to:

  • Creating new documents from scratch (every run)
  • Setting default style font (set_style_font())
  • Filling table cells (set_tc_text() already includes this fix)
  • Any code that sets run.font.name for Chinese content

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.