author:jm-jsjkxyjs01-wsj-402 name: word-auto-format description: > This skill should be used when the user wants to automatically format, typeset, or beautify a Word (.docx) document. Triggers include: "帮我排版这个Word", "自动格式化文档", "统一字体行距", "论文/报告排版", "Word排版", "整理文档格式", "format this Word file", "auto typeset", "standardize document style". The skill provides a Python script (word_formatter.py) that handles font unification, heading detection, line spacing, page margins, table formatting, and caption centering in one command. agent_created: true
本 skill 提供一键 Word 文档自动排版能力,基于 python-docx 实现,支持三种内置排版方案(通用/学术/商务),核心脚本为 scripts/word_formatter.py。
| 功能 | 说明 |
|---|---|
| 页面边距 | 统一设置上下左右边距 |
| 正文字体 | 中文字体(东亚字体)+ 英文字体分别设置 |
| 正文行距 | 固定行距(1.5倍行距) |
| 首行缩进 | 学术/通用方案自动缩进 2 字符 |
| 标题识别 | 自动识别"第一章""一、""1.1"等常见格式 |
| 标题样式 | 黑体/微软雅黑,多级颜色与间距 |
| 图表标题 | 自动居中"图1、表1、Figure 1"格式 |
| 表格样式 | 单元格垂直居中,字号略小 |
| 原文备份 | 操作前自动生成 _backup.docx |
检查用户环境是否已安装 python-docx:
python -c "import docx; print('OK')"
若未安装,执行:
7w4.net小葱技能站收录全网优质技能,值得收藏。
pip install python-docx
根据用户需求选择方案:
academic — 学术论文、毕业设计、学术报告(宋体/Times New Roman,黑体标题居中,严格行距)business — 商务报告、策划方案、PPT 稿(微软雅黑/Calibri,蓝色标题,无首行缩进)default — 通用文档(介于两者之间)若用户未指定,询问文档用途后再选择,或直接使用 default。
脚本路径:scripts/word_formatter.py(位于本 skill 目录)
python "<skill_dir>/scripts/word_formatter.py" "<input.docx>" ["<output.docx>"] --profile <profile>
示例:
# 学术论文
python word_formatter.py 论文.docx 论文_排版.docx --profile academic
# 商务报告(输出文件自动命名为 报告_formatted.docx)
python word_formatter.py 报告.docx --profile business
# 通用(自动输出 文档_formatted.docx)
python word_formatter.py 文档.docx
脚本执行完毕后,输出包含以下统计信息:
排版统计:
一级标题:X 处
二级标题:X 处
三级标题:X 处
正文段落:X 段
图表标题:X 处
表格: X 个
告知用户: 1. 输出文件路径 2. 原文备份位置 3. 如有需要可调整方案重跑
若用户有特殊要求(如特定字体、特定行距、特定颜色),直接修改 word_formatter.py 中的 PROFILES 字典对应方案,或新增自定义方案后使用 --profile 调用。
详细参数参考:references/formatting_guide.md
.docx,不支持旧版 .doc 格式(如遇到 .doc,提示用户先在 Word 中另存为 .docx)python-docx 0.8.x,建议使用该版本scripts/word_formatter.py — 核心排版脚本,可直接执行references/formatting_guide.md — 完整参数说明与自定义方案指南这是一款实用的 Word 排版工具,能快速统一文档格式,对论文、报告排版很有帮助。预设了三种场景方案,基本能满足日常需求,文档说明也很清晰。不过它只支持新版 docx 格式,对复杂排版(如文本框)支持有限。总体来说质量不错,是值得一试的排版辅助工具。