DOCX 精确排版控制 Skill
使用 python-docx 进行精确的 Word 文档排版。
操作模式
当用户提出 Word 文档相关需求时,调用 scripts/docx_skill.py:
python scripts/docx_skill.py <操作> <参数JSON文件>
参数通过 JSON 文件传递(避免命令行注入),结果通过 stdout 返回 JSON。
支持的操作
| 操作 |
描述 |
关键参数 |
create |
创建新文档 |
title, content_sections |
open_edit |
打开并编辑现有文档 |
path, edits[] |
find_replace |
查找替换文本(保留格式) |
path, find, replace |
add_table |
添加/编辑表格 |
path, rows, cols, data |
merge_docs |
合并多个文档 |
paths[], output_path |
add_toc |
生成目录 |
path |
add_header_footer |
设置页眉页脚 |
path, header_text, footer_text |
add_comment |
添加批注 |
path, text, comment |
set_style |
应用样式模板 |
path, template_path |
track_changes |
启用/接受修订 |
path, action |
输出格式
{
"success": true,
"output_path": "文档保存路径",
"message": "操作结果描述",
"pages": 5,
"tables": 3,
"images": 2
}
依赖
pip install python-docx
注意事项
- 所有路径使用绝对路径
- 编码统一 UTF-8
- 编辑操作自动备份原文件(
.bak)
1---2name: docx3description: Word精确排版控制 — 创建/编辑DOCX文档、表格、样式、修订模式、批注4---56# DOCX 精确排版控制 Skill78使用 `python-docx` 进行精确的 Word 文档排版。910## 操作模式1112当用户提出 Word 文档相关需求时,调用 `scripts/docx_skill.py`:1314```python15python scripts/docx_skill.py <操作> <参数JSON文件>16```1718参数通过 JSON 文件传递(避免命令行注入),结果通过 stdout 返回 JSON。1920## 支持的操作2122| 操作 | 描述 | 关键参数 |23|------|------|---------|24| `create` | 创建新文档 | title, content_sections |25| `open_edit` | 打开并编辑现有文档 | path, edits[] |26| `find_replace` | 查找替换文本(保留格式) | path, find, replace |27| `add_table` | 添加/编辑表格 | path, rows, cols, data |28| `merge_docs` | 合并多个文档 | paths[], output_path |29| `add_toc` | 生成目录 | path |30| `add_header_footer` | 设置页眉页脚 | path, header_text, footer_text |31| `add_comment` | 添加批注 | path, text, comment |32| `set_style` | 应用样式模板 | path, template_path |33| `track_changes` | 启用/接受修订 | path, action |3435## 输出格式3637```json38{39 "success": true,40 "output_path": "文档保存路径",41 "message": "操作结果描述",42 "pages": 5,43 "tables": 3,44 "images": 245}46```4748## 依赖4950```bash51pip install python-docx52```5354## 注意事项55- 所有路径使用绝对路径56- 编码统一 UTF-857- 编辑操作自动备份原文件(`.bak`)