Back to Skills
Office AutomationFreev1.1.0
npx skills add lovstudio/fill-form-skill

lovstudio:fill-form

Fill Word document form templates (.docx) with structured data. Auto-detects table-based form fields (label โ†’ value cell pairs), supports CJK/Latin mixed text with proper font switching, merged cells, and paragraph-based forms.

Part of lovstudio/skills โ€” by lovstudio.ai

Install

npx skills add lovstudio/skills --skill lovstudio:fill-form

Requires: Python 3.8+ and pip install python-docx

How It Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Template (.docx)                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚ ไธป่ฎฒไบบ   โ”‚           โ”‚ ่Œ็งฐ     โ”‚          โ”‚ โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚
โ”‚  โ”‚ ๅ•ไฝ     โ”‚                                 โ”‚ โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚
โ”‚  โ”‚ ่ฎฒๅบง้ข˜็›ฎ โ”‚           โ”‚ ๆ—ถ้—ด     โ”‚          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                     โ”‚ --scan โ†’ detect fields
                     โ”‚ --data โ†’ fill values
                     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Filled (.docx)                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚ ไธป่ฎฒไบบ   โ”‚ ๅผ ไธ‰      โ”‚ ่Œ็งฐ     โ”‚ ๆ•™ๆŽˆ     โ”‚ โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚
โ”‚  โ”‚ ๅ•ไฝ     โ”‚ ๅŒ—ไบฌๅคงๅญฆ                        โ”‚ โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚
โ”‚  โ”‚ ่ฎฒๅบง้ข˜็›ฎ โ”‚ AIไธŽๆœชๆฅ  โ”‚ ๆ—ถ้—ด     โ”‚ 4ๆœˆ10ๆ—ฅ  โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Usage

Step 1 โ€” Scan the template to see all detected fields:

python fill_form.py --template form.docx --scan

Output:

Detected 6 form fields:

  1. ไธป่ฎฒไบบ
  2. ่Œ็งฐ
  3. ๅ•ไฝ
  4. ่ฎฒๅบง้ข˜็›ฎ
  5. ๆ—ถ้—ด
  6. ๅœฐ็‚น

--- JSON ---
{
  "ไธป่ฎฒไบบ": "",
  "่Œ็งฐ": "",
  ...
}

Step 2 โ€” Fill with a JSON data file or inline JSON:

# From JSON file
python fill_form.py --template form.docx --data-file data.json

# Inline JSON
python fill_form.py --template form.docx \
  --data '{"ไธป่ฎฒไบบ": "ๅผ ไธ‰", "่Œ็งฐ": "ๆ•™ๆŽˆ", "ๅ•ไฝ": "ๅŒ—ไบฌๅคงๅญฆ"}'

Output saves to the same directory as the template (form_filled.docx).

Options

OptionDefaultDescription
--template(required)Path to template .doc/.docx
--output<name>_filled.docxOutput path (defaults to template directory)
--scanList all detected form fields
--dataJSON string with field โ†’ value mapping
--data-filePath to JSON file with field โ†’ value mapping
--fontPlatform CJK serifFont for filled text
--font-size11Font size in points

Field Detection

The script detects fillable fields in three ways:

MethodHow it worksExample
Table cellsLabel in one cell, blank value in adjacent cellโ”‚ ๅง“ๅ โ”‚ ___ โ”‚
Merged rowsFull-width cell with Label๏ผš patternโ”‚ ๅค‡ๆณจ๏ผš________________ โ”‚
ParagraphsFallback for docs without tablesๅง“ๅ๏ผš followed by blank line

Fields are matched by normalized label (whitespace-insensitive), so ไธป ่ฎฒ ไบบ matches ไธป่ฎฒไบบ.

Supported Formats

FormatSupport
.docxFull support (recommended)
.docAuto-converts via textutil (macOS) or LibreOffice. Table structure may be lost โ€” convert to .docx first for best results.

License

MIT

formfilltemplatedocxwordtablecjk