可复用的 Word 表格填写系统。解包 → 去重 → 扫描标签 → 填表 → 还原 → 打包,全程只读原文档。
git clone https://github.com/shortFisherman/auto_tab.git
cd auto_tab
pip install -r requirements.txt依赖:Python 3.10+、lxml、defusedxml、openai、python-dotenv。无需 Word 应用程序。
# 一条命令:AI 自动填表
python -m src auto documents/6.docx info/6.md --output results/6.docxAI 会根据 Markdown 信息文档自动匹配表单标签。原则:可精简不可新增 — 日期格式可以适配,但绝不编造信息。
python -m src auto documents/模板.docx info/信息.md --output results/结果.docx程序自动完成:解包 → 去重 → 扫描标签 → AI 填写 → 打包。一步到位。
AI 会根据 Markdown 信息文档的内容自动匹配表单标签。原则:可精简不可新增 — 日期格式可以适配,但绝不编造信息。
配置文件 .env(项目根目录):
AI_API_KEY=sk-xxx # API Key
AI_BASE_URL=https://api.deepseek.com # API 地址,默认 DeepSeek
AI_MODEL=deepseek-chat # 模型名称兼容 DeepSeek、OpenAI、Ollama 等任何 OpenAI 兼容 API。
# 1. 准备:生成字典模板
python -m src prepare documents/模板.docx --output dicts/模板.json
# 2. 打开 dicts/模板.json,把空值填上
# 3. 运行:填表 → 打包
python -m src run dicts/模板.json documents/模板.docx results/结果.docxpython -m src auto <input.docx> <info.md> --output <output.docx> [-q] # 一条龙
python -m src prepare <input.docx> [--output <dict.json>] [-q] # 生成模板
python -m src run <dict.json> <input.docx> <output.docx> [-q] # 填表打包
-q / --quiet 隐藏逐格填写日志。
{
"normal": {
"姓名": "江月",
"性别": "男"
},
"header_tables": [
{
"headers": ["学校", "起止时间", "是否最高学历"],
"data": [
["安庆一中", "2010-09/2013-06", "否"],
["合肥工大", "2013-09/2017-06", "是"]
]
}
]
}├── src/
│ ├── pipeline.py ← 编排层
│ ├── dedup.py ← 重复文本处理
│ ├── scanner.py ← 标签扫描
│ ├── fill.py ← 填表引擎
│ ├── ai_fill_template.py ← AI 自动填表
│ ├── _xml_utils.py ← XML 工具
│ ├── cli.py ← CLI 入口
│ └── _office/ ← 解包/打包(自包含)
├── dicts/ ← 字典模板 + 填写结果
├── documents/ ← 原始 .docx 模板
├── info/ ← Markdown 信息文档
├── results/ ← 填表输出的 .docx
└── .cache/ ← 临时缓存(自动清理)
MIT