legal-aid-doc

Fill Word legal aid document templates from key-value element files while preserving formatting.

1|Updated Mar 25, 2026
One-click install
npx skills add https://github.com/qfwc258/trae-skills --skill legal-aid-doc-qfwc258
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: legal-aid-doc
Source: https://github.com/qfwc258/trae-skills/tree/main/legal-aid-doc
Command: npx skills add https://github.com/qfwc258/trae-skills --skill legal-aid-doc-qfwc258

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires python-docx.

What problem does it solve? Legal aid caseworkers must repeatedly fill the same case data into many Word closure documents (结案报告, 阅卷笔录, 代理意见, etc.), which is error-prone and time-consuming. This Skill batch-fills multiple .docx templates from a single element file while keeping the original document formatting intact. ## Core Features & Use Cases - Batch Template Filling: Reads an element file (元素_*.txt) with key::value pairs and fills every matching .docx template in a directory, producing *_已填充.docx outputs. - Format Preservation: Uses python-docx with character-level format tracking, XML-level font handling, and checkbox (□/☑) protection so the original layout is unchanged. - Multi Case-Type Support: Auto-detects civil, criminal, administrative, state compensation, and labor arbitration cases, with required-field validation per type. - Advanced Placeholders: Supports {key}, {{key}}, 【key】, [key] and more, plus default values, format specs, incremental fill, backups, logging, and rollback. - Use Case: A legal aid center prepares 元素_民事.txt for a labor dispute case, then runs one command to generate filled versions of 法援结案.docx, 阅卷笔录.docx, and 承办情况小结.docx in a single batch. ## Quick Start Place your 元素_民事.txt and .docx templates in one folder, then ask the assistant to run fill_docx_pro.py to batch-fill all legal aid templates with the case data.

Frequently Asked Questions about legal-aid-doc

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fill Word templates with data in Python?

Use python-docx to open the .docx template, replace placeholder keys with values from a parsed data file, and save a new document. This tool processes paragraphs, tables, headers, and footers while copying each run's font, size, and color to the replacement text.

How to fill multiple Word documents from one data file?

Place all .docx templates in one directory with a key-value element file, then run fill_docx_pro.py with the directory path. It globs matching templates, parses the element file once, and generates a filled copy of each template with a _已填充 suffix.

Does python-docx preserve formatting when replacing text?

Not by default, since replacing run text can drop character formatting. This tool records per-character format attributes, replaces from back to front to avoid position shifts, and reapplies fonts via XML rFonts elements to keep the original layout.

What placeholder formats are supported in Word templates?

Supported formats include {key}, {{key}}, [key], [[key]], 【key】, <key>, <<key>>, #key#, and $key$. Enhanced mode also supports default values like {key?default} and format specs such as {date:date:%Y年%m月%d日}.

Why are my filled Word documents losing checkbox symbols?

Checkbox characters like □ and ☑ use symbol fonts that get lost during naive text replacement. The tool detects these characters, preserves them during substitution, and reapplies symbol fonts such as Wingdings to the affected runs.

Can I recover a Word document after a bad fill operation?

Yes. The document manager module creates timestamped backups in a backup directory before filling and logs every operation to JSONL files. You can roll back any file to its latest backup or a specific historical version.