Word Template Filler

👤 winezzz999 📦 v1.0.0 ⭐ 4.4 ⬇️ 302 下載
📄 辦公效率 免費

📖 技能介紹

Word Template Filler Skill

Fill/edit Word .docx templates on Windows via win32com COM automation — preserves ALL formatting, images, underlines, page breaks, and table layout.

Why win32com instead of python-docx

Approach Format/Image Preservation Requires Word
win32com (this skill) ✅ 100% — Word does the work ✅ Yes
python-docx ❌ Drops images, corrupts complex formatting ❌ No
docxtpl (Jinja) ⚠️ Better than python-docx, still risks layout drift ❌ No

Requirements

  • Windows with Microsoft Word installed
  • pywin32 (pip install pywin32)

Quick Start

# Fill cover fields, append answers, add page breaks — all in one command
python {scripts}/word_template_filler.py template.docx report.docx ^
  --cover-field "所在學院:鐵道工程學院" ^
  --cover-field "專業年級:車輛工程 2023級" ^
  --page-break-before "C2.轉向架" ^
  --find-replace "。?:。"

Commands

All operations use the bundled scripts/word_template_filler.py CLI tool.

7w4.net有更好的技能外掛。

--cover-field / -c

Fill a cover page field (preserves underline lines).

--cover-field "label:value"

The label must exactly match the text before the colon (including spaces). The value is inserted before the underlined spaces, so the fill-in line remains.

--append-answer / -a

Append answer text after a question in a table cell.

--append-answer "TableIdx:Row:Col:question text||answer text"

Example: --append-answer "2:3:1:1、轉向架的作用是什麼?||1. 可相對車體迴轉..."

--insert-blank-para / -p

Insert text into a blank paragraph within a table cell (for sub-tables).

--insert-blank-para "TableIdx:Row:Col:Para1B:text"

Para1B = 1-based paragraph index within the cell. Use debug mode to find indices.

--page-break-before / -b

Insert a page break before a heading.

--page-break-before "C2.轉向架"

--find-replace / -r

Find and replace text across the entire document (preserves formatting).

--find-replace "find:replace"

--set-time-score / -t

Set 實訓時間 and 得分 fields in a section table row.

--set-time-score "TableIdx:time|score"

Example: --set-time-score "2:2026年6月|95"

--visible

Show the Word window during processing (for debugging).

Debug Mode

# First, kill any hanging Word processes
taskkill /f /im WINWORD.EXE

# Show Word window to watch the process
python {scripts}/word_template_filler.py template.docx debug.docx --visible

To find paragraph indices within a table cell, use this diagnostic snippet:

import win32com.client as win32
word = win32.gencache.EnsureDispatch('Word.Application')
word.Visible = False
doc = word.Documents.Open(r'path\to\template.docx')
cell = doc.Tables(2).Cell(4, 1)  # Table 2, Row 4, Col 1
paras = cell.Range.Paragraphs
for i in range(paras.Count):
    txt = repr(paras(i+1).Range.Text)[:80]
    print(f"  Para {i}: {txt}")
doc.Close(False)
word.Quit()

Verification Checklist

  1. Cover: underlined spaces preserved
  2. Page breaks: sections start on correct pages
  3. Punctuation: no 。? or !? double-patterns
  4. Content: tables have data, text is readable

Known Pitfalls

Don't Do Why
doc.Range().Text = ... Destroys ALL formatting, images, tables
Replace paragraph containing \f Loses page break
Use python-docx to save modified template Loses images, complex formatting
\n in Find patterns Word uses \r (chr 13) for paragraph marks
Replace cover paragraph text blindly Destroys underlined spaces
Forget cleanup after --append-answer May leave extra characters

🤖 AI 評測

這個 Skill 質量不錯,文件寫得很詳細,小白也能快速上手。它通過呼叫 Word 軟體本身來填充模板,能很好地保留原始格式、圖片和下劃線,不會出現亂碼問題。不過它只能在 Windows 系統上使用,而且電腦必須裝了 Microsoft Word 軟體。總體來說,如果你經常需要批次處理 Word 文件表格,這是個值得一試的工具。

📊 多維度評分

適應性4.6
規範性4.6
有效性4
可靠性4
可信度4.9

📁 包含檔案 (4 個)

📄 SKILL.md 3.7 KB
📄 _meta.json 136 B
📄 scripts/word_template_filler.py 6.8 KB
📄 skill-card.md 1.8 KB