gongwen-format-gbt9704
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "gongwen-format-gbt9704" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-76094f0e967f298484d90482675e8812b2ae6710659d9c6e54dc5484348ed28a. Verify the upstream source and version against https://skillhub.cn/skills/user_905ff2ca/gongwen-format-gbt9704 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Convert arbitrary text into a Word document formatted to GB/T 9704-2012. Formats body text according to the standard (FangSong size 3 / 16pt, bold HeiTi for level‑1 headings, bold KaiTi for level‑2 headings, fixed 28pt line spacing, first‑line indent of 2 characters). Offers three modes: Default formatting / auto intelligent recommendation / custom toggle. Accepts Markdown, plain text, JSON, and DOCX inputs, exports to PDF, and supports batch processing. Only changes formatting, not content. Includes environment self-check and compatibility with multi‑agent installation. v1.5.0 fixes Markdown table retention and optimizes interaction logic.
Introduction source: third_party · user_905ff2ca · 1.5.0 Reference
SkillPi interpretation
- Inputs and outputs
- bash
- Software, accounts and paid services
- python3 "$SCRIPT" --check-env
- Testing
- Not tested
Browse files
Frontmatter
name: gongwen-format
slug: gongwen-format-gbt9704
displayName: 文档排版格式化
description: >-
把任意文本一键转为格式规范的Word文档。按国标GB/T 9704-2012参数格式化正文
(仿宋三号16pt、黑体一级标题、楷体二级标题加粗、28pt固定行距、首行缩进2字),
三种模式可选:默认格式化/auto智能推荐/自定义开关。
支持Markdown/纯文本/JSON/DOCX输入,PDF导出,批量处理。只管格式,不管内容。
自带环境自检和多Agent安装兼容。v1.5.0修复Markdown表格保留,优化交互逻辑。
version: 1.5.0
author: SOLO
category: office-efficiency
tags:
- 文档排版
- 格式化
- GB/T 9704
- 红头文件
- 封面
- 页码
- Word
- docx
- Markdown转Word
- PDF导出
trigger:
- 转换
- 转成
- 排版
- 格式化
- 调整
- 生成
- 做成
- 规范
- 标准化
- 转成公文
- 转成政府公文
- 转成红头文件
- 转换公文格式
- 排版一下
- 排版规范
- 调整格式
- 格式不对
- 字体不对
- 行距不对
- 按国标排版
- 按GB/T 9704排版
- 做成Word文档
- 生成docx
- 转成docx
- 加红头
- 加封面
- 加页码
- 排版
- 格式化
- 文档格式
- 排版规范
- 字体字号
- 行距
- 红头文件
- 封面
- 页码
- docx
- Word文档
- Markdown转Word
- GB/T 9704
- 仿宋
- 黑体
- 楷体
- 小标宋
- 函
- 通知
- 报告
- 请示
- 批复
- 意见
- 公告
- 通告
- 命令
- 议案
- 纪要
- 通报
- 解决方案
- 可研报告
- 技术方案
- 投标文件
- 合同
- 协议
- 商业计划书
- 工作总结
- 白皮书
- 验收报告
- 用户手册
- 规划
- 计划
- 方案
- 制度
- 办法
- 规定
- 简报
- 分析报告
- 评估报告
permission: read_write
dependency:
- python-docx
- LibreOffice(PDF导出可选)
pricing: free文档排版格式化
脚本路径定位(重要)
本skill的脚本位于skill安装目录下的 scripts/generate_gongwen.py。不同Agent的安装目录不同,执行前必须先定位到正确路径:
| Agent | skill安装目录 | 脚本完整路径 |
|---|---|---|
| Trae / TRAE SOLO | ~/.trae-cn/skills/gongwen-format/ |
~/.trae-cn/skills/gongwen-format/scripts/generate_gongwen.py |
| Claude Code | ~/.claude/skills/gongwen-format/(软链接到trae) |
~/.claude/skills/gongwen-format/scripts/generate_gongwen.py |
| Codex | ~/.codex/skills/@user_xxx/gongwen-format-gbt9704/ |
~/.codex/skills/@user_xxx/gongwen-format-gbt9704/scripts/generate_gongwen.py |
| Cursor | ~/.cursor/skills/gongwen-format/ |
~/.cursor/skills/gongwen-format/scripts/generate_gongwen.py |
| WorkBuddy/CodeBuddy | ~/.workbuddy/skills-marketplace/skills/gongwen-format/ |
同上 + scripts/generate_gongwen.py |
| Qoder | 项目级 .qoder/skills/ 或全局配置 |
按实际安装位置定位 |
定位方法(通用,适用于所有Agent):
# 方法1:从SKILL.md所在目录推导
SCRIPT_DIR="$(dirname "$(find ~ -path '*/gongwen-format/scripts/generate_gongwen.py' 2>/dev/null | head -1)")"
SCRIPT="$SCRIPT_DIR/generate_gongwen.py"
# 方法2:直接用相对路径(当工作目录就是skill目录时)
# python3 scripts/generate_gongwen.py input.md output.docx
执行前必须确保依赖已安装:
# 首次使用前,先运行环境自检
python3 "$SCRIPT" --check-env
# 如果自检提示python-docx未安装,执行安装
pip install python-docx --break-system-packages
把任意文本(Markdown / 纯文本 / JSON / docx)一键转为格式规范的 Word 文档。
智能交互规则
当用户要求排版、格式化、转换文档格式时,按以下规则处理:
- 用户已明确指定结构元素(如说了"红头""封面""页码""签发人"等关键词)-> 直接构造对应参数执行,无需询问
- 用户只说"排版/格式化/调整"但未指定要什么 -> 展示三选一让用户选择
- 用户说"你帮我判断""auto""自动" -> 直接执行auto模式
- 批处理/API调用场景 -> 直接按传入参数执行
当需要展示三选一时,向用户展示以下选择:
请选择排版模式:
1. 默认格式化 -- 只规范正文字体字号行距缩进页边距(国标参数),不加红头/封面/页码。适合"帮我把这段文字排版规范一点"。
2. auto智能推荐 -- 根据标题关键词自动判断文档类型,智能推荐该加什么(封面/红头/页码)。适合"我不确定该加什么,你帮我判断"。
3. 自定义 -- 逐项选择需要加什么(封面/红头/版记/页码/签发人等)。适合"我知道要什么,精确控制"。
用户选择后,再根据模式执行对应命令。如果用户未明确选择,默认推荐 模式2 auto。
快速路径:如果用户已在消息中指定了所需参数(如"红头+页码+发文机关XX公司"),直接构造命令执行即可,无需展示三选一。三选一仅在用户需求不明确时使用。
模式1:默认格式化
只做正文格式化,把字体字号行距缩进页边距调为国标规范,不加任何结构元素。
python3 scripts/generate_gongwen.py input.md output.docx
效果:仿宋三号正文 + 黑体一级标题 + 楷体二级标题 + 28pt行距 + 首行缩进2字 + 页边距3.7/3.5/2.8/2.6cm。无红头、无封面、无页眉、无页码。
适合:已有内容只想让格式规范、不需要任何版头版记的场景。
模式2:auto智能推荐
根据标题关键词自动判断文档类型,智能推荐该加封面/红头/页码。
python3 scripts/generate_gongwen.py input.md output.docx --auto
推荐规则:
| 标题含关键词 | 自动推荐 | 场景 |
|---|---|---|
| 函/请示/报告/通知/通报/决定/纪要/批复/意见/公告/通告/命令/议案/批示/回函/答复 | 红头+页码 | 正式文书 |
| 解决方案/可研/建议书/实施方案/技术方案/验收/总结/商业计划书/白皮书/规划/计划/方案/制度/办法/简报/分析报告/评估报告/审计报告/测试报告 | 封面+页码 | 方案报告 |
| 合同/协议/备忘录/意向书/契约/承诺书/声明/授权书/委托书/证明 | 页码 | 简洁格式 |
| 投标/招标/应答文件/竞标/标书/报价单/投标函/投标书 | 封面+页码 | 提示以招标文件为准 |
| 其他 | 页码 | 默认 |
auto推荐红头时,需配合
--redhead "单位名称"才会实际生成红头。未提供单位名称则跳过红头,其余选项正常生效。
适合:不确定文档该用什么格式,让脚本自动判断。
模式3:自定义
逐项选择需要添加的结构性元素,精确控制。
python3 scripts/generate_gongwen.py input.md output.docx \
--cover --organization "XX科技有限公司" --date "2024年3月" --page-number
可选开关:
| 参数 | 作用 | 默认 |
|---|---|---|
--cover |
生成封面页(标题+单位+日期+分页) | 关 |
--organization "名称" |
封面上的编制单位 | 空 |
--date "日期" |
封面上的日期 | 当前日期 |
--redhead "发文机关" |
生成红头版头 | 关 |
--redhead-color black |
红头用黑色(企业红头) | 红色FF0000 |
--doc-number "文号" |
发文字号(六角括号〔〕) | 空 |
--issuer "姓名" |
签发人 | 空 |
--copy-to "机关" |
抄送机关(触发版记生成) | 空 |
--issue-office "机关" |
印发机关(触发版记生成) | 空 |
--issue-date "日期" |
印发日期 | 空 |
--page-number |
生成页码 | 关 |
--title "标题" |
手动指定标题(覆盖自动识别) | 自动 |
--subtitle "副标题" |
副标题 | 空 |
--pdf |
同时导出PDF | 关 |
--batch |
批量目录处理 | 关 |
--quiet |
静默模式,不输出提示信息 | 关 |
适合:明确知道自己要什么,精确控制每个元素。
文档类型对照
| 你想做的文档 | 推荐模式 | 推荐命令 |
|---|---|---|
| 工作函 | 自定义 | --redhead "单位" --doc-number "文号" --page-number |
| 请示/报告 | 自定义 | --redhead "单位" --doc-number "文号" --page-number |
| 通知/通报 | 自定义 | --redhead "单位" --doc-number "文号" --page-number |
| 解决方案 | 自定义 | --cover --organization "单位" --date "日期" --page-number |
| 可研报告 | 自定义 | --cover --organization "单位" --date "日期" --page-number |
| 技术方案 | 自定义 | --cover --organization "单位" --page-number |
| 商业计划书 | 自定义 | --cover --organization "单位" --date "日期" --page-number |
| 合同/协议 | 自定义 | --page-number |
| 会议纪要 | auto | --auto --redhead "单位" --doc-number "文号" |
| 投标文件 | 自定义 | --cover --organization "单位" --date "日期" --page-number |
| 工作总结 | 自定义 | --cover --organization "单位" --date "日期" --page-number |
| 只想排版 | 默认 | (不加任何参数) |
| 不确定用什么 | auto | --auto |
格式规范(国标 GB/T 9704-2012)
所有模式共用以下参数,来源于国标,不可变:
| 要素 | 字体 | 字号 | 其他 |
|---|---|---|---|
| 主标题 | 小标宋 | 二号 22pt | 居中 |
| 正文 | 仿宋 | 三号 16pt | 首行缩进2字(32pt) 行距28pt固定 |
| 一级标题 一、 | 黑体 | 三号 16pt | 不加粗 |
| 二级标题 (一) | 楷体 | 三号 16pt | 加粗 |
| 三级标题 1. | 仿宋 | 三号 16pt | 加粗 |
| 四级标题 (1) | 仿宋 | 三号 16pt | 不加粗 |
| 页边距 | - | - | 上3.7 / 下3.5 / 左2.8 / 右2.6 cm |
| 页码 | 宋体 | 四号 14pt | 单页右空一字 / 双页左空一字 / 一字线格式 |
| 红头 | 小标宋 | 自适应 | 红色FF0000 |
| 发文字号 | 仿宋 | 三号 16pt | 六角括号〔〕 不编虚位 |
| 签发人 | 仿宋+楷体 | 三号 16pt | "签发人:"仿宋 + 姓名楷体 |
| 红色分隔线 | - | - | FF0000 |
| 成文日期 | 仿宋 | 三号 16pt | 右空四字 阿拉伯数字不编虚位 |
| 版记 | 仿宋 | 四号 14pt | 抄送/印发机关 + 分隔线 |
封面格式(行业惯例)
| 要素 | 字体 | 字号 |
|---|---|---|
| 封面标题 | 黑体 | 小初号 36pt 加粗 |
| 副标题 | 黑体 | 一号 26pt |
| 编制单位 | 黑体 | 三号 16pt |
| 编制日期 | 宋体 | 三号 16pt |
排版效果
默认模式
- 标题:小标宋二号22pt居中
- 一级标题"一、":黑体三号16pt
- 二级标题"(一)":楷体三号16pt加粗
- 三级标题"1.":仿宋三号16pt加粗
- 正文:仿宋三号16pt,首行缩进2字,行距28pt固定
- 页边距:上3.7/下3.5/左2.8/右2.6cm
- 无红头、无封面、无页眉、无页码
加 --cover
- 封面页:标题小初号36pt黑体加粗居中 + 编制单位三号黑体 + 日期三号宋体 + 分页
- 正文页同默认模式
加 --redhead
- 红头:发文机关名称小标宋红色FF0000 + "文件"二字
- 发文字号:仿宋三号16pt 六角括号〔〕
- 红色分隔线
- 正文同默认模式
加 --page-number
- 页脚:宋体四号14pt,单页右空一字/双页左空一字,一字线格式"- 1 -"
Markdown 输入支持
| Markdown | 映射为 | 格式 |
|---|---|---|
# 标题 |
主标题 | 小标宋二号居中 |
## 一级 |
一级标题 | 黑体三号 |
### 二级 |
二级标题 | 楷体三号加粗 |
#### 三级 |
三级标题 | 仿宋三号加粗 |
##### 四级 |
四级标题 | 仿宋三号 |
纯文本输入时,按"一、""(一)""1.""(1)"自动识别层级。
完整调用示例
以下命令假设当前工作目录为skill安装目录。如不在skill目录,请用上文的"脚本路径定位"方法获取完整路径。
# 模式1:默认格式化
python3 scripts/generate_gongwen.py input.md output.docx
# 模式2:auto智能推荐
python3 scripts/generate_gongwen.py input.md output.docx --auto
# 模式3:自定义 -- 正式函件(红色红头)
python3 scripts/generate_gongwen.py input.txt output.docx \
--redhead "XX科技有限公司" --doc-number "XX函〔2024〕5号" --page-number
# 模式3:自定义 -- 企业红头(黑色)
python3 scripts/generate_gongwen.py input.txt output.docx \
--redhead "XX科技有限公司" --redhead-color black \
--doc-number "XX发〔2024〕12号" --issuer "张三" --page-number
# 模式3:自定义 -- 解决方案(封面+页码)
python3 scripts/generate_gongwen.py input.md output.docx \
--cover --organization "XX科技有限公司" --date "2024年3月" --page-number
# 模式3:自定义 -- 合同(只要页码)
python3 scripts/generate_gongwen.py input.txt output.docx --page-number
# 模式3:自定义 -- 红头+版记(完整公文)
python3 scripts/generate_gongwen.py input.txt output.docx \
--redhead "XX科技有限公司" --doc-number "XX发〔2024〕12号" \
--copy-to "XX局" --issue-office "XX办公室" --issue-date "2024年3月1日" \
--page-number
# PDF导出
python3 scripts/generate_gongwen.py input.md output.docx --pdf
# 批量处理
python3 scripts/generate_gongwen.py input_dir/ output_dir/ --batch --auto
# 静默模式
python3 scripts/generate_gongwen.py input.md output.docx --auto --quiet
依赖安装与自检
首次使用前,运行环境自检(自动检测python-docx、字体、LibreOffice):
python3 scripts/generate_gongwen.py --check-env
自检会告诉你缺什么、怎么装。核心依赖只有 python-docx:
pip install python-docx --break-system-packages
PDF导出可选安装LibreOffice:
- macOS:
brew install --cask libreoffice - Linux:
sudo apt install libreoffice
多Agent安装指南
本skill支持通过SkillHub安装到各种AI Agent。安装方式如下:
| Agent | 安装命令 | 说明 |
|---|---|---|
| Trae / TRAE SOLO | skillhub install gongwen-format-gbt9704 |
安装到 ~/.trae-cn/skills/ |
| Claude Code | skillhub install gongwen-format-gbt9704 或软链接 |
软链接:ln -s ~/.trae-cn/skills/gongwen-format ~/.claude/skills/gongwen-format |
| Codex | skillhub install gongwen-format-gbt9704 |
安装到 ~/.codex/skills/@user_xxx/ |
| Cursor | skillhub install gongwen-format-gbt9704 |
安装到 ~/.cursor/skills/ |
| WorkBuddy | 从marketplace安装或手动复制到 ~/.workbuddy/skills-marketplace/skills/ |
|
| Qoder | 项目级或全局配置目录放入skill文件夹 |
通用安装保障:无论哪个Agent,安装后必须确认两点:
- skill目录下有
SKILL.md和scripts/generate_gongwen.py - 运行
python3 scripts/generate_gongwen.py --check-env通过环境自检
变更记录
| 版本 | 核心变化 |
|---|---|
| v1.5.0 | 修复Markdown表格保留;优化强制三选一为智能交互;修复合同短行误判标题 |
| v1.4.0 | 新增--check-env环境自检;新增多Agent安装指南和脚本路径定位 |
| v1.3.1 | 强制三选一交互 |
| v1.2.0 | 触发词扩展70+,auto关键词扩充60+,错误处理增强 |
| v1.0.2 | 从档位制改为默认+可选开关制,--auto智能推荐 |
常见问题
Q: 生成的文档打开后字体显示不对? A: 需要安装国标字体。Windows自带仿宋/黑体/楷体;macOS需安装"方正仿宋_GBK""方正黑体_GBK""方正楷体_GBK""方正小标宋_GBK"或从网上下载"仿宋_GB2312""黑体""楷体_GB2312""方正小标宋简体"。脚本会自动fallback到系统已有字体。
Q: 如何生成红头文件?
A: 选择模式3自定义,使用 --redhead "单位名称" 参数。红色红头加 --doc-number "文号" --page-number。企业黑色红头加 --redhead-color black。
Q: --auto模式推荐了红头但没有实际生成?
A: auto推荐红头后需要配合 --redhead "单位名称" 参数提供发文机关名称,否则会跳过红头。
Q: 投标文件格式有特殊要求怎么办? A: 投标文件格式必须以招标文件要求为准。--auto检测到"投标"时会提示,建议先查看招标文件的格式要求再决定参数。
Q: 如何批量处理多个文件?
A: 使用 --batch 参数,输入和输出都指定目录:python3 generate_gongwen.py input_dir/ output_dir/ --batch --auto
Q: PDF导出失败?
A: PDF导出需要安装LibreOffice。macOS: brew install --cask libreoffice,Linux: sudo apt install libreoffice。
Q: 三个模式有什么区别? A: 模式1默认只规范正文字体行距,不加任何结构元素;模式2 auto根据标题自动判断该加什么;模式3自定义由你逐项选择。不确定时选模式2。
Current listing version
1.5.0
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供文档排版格式化功能,按国标GB/T 9704-2012参数格式化正文
- 支持多种输入输出格式(Markdown/纯文本/JSON/DOCX输入,PDF导出)
- 具有明确的办公效率提升价值,属于通用工具
Highlights
- 触发词覆盖全面,包含'转换''排版''格式化''调整''生成''规范''标准化'等多种变体
- 边界清晰,能有效区分不同文档处理需求
Highlights
- 文档结构完整,包含三种模式的详细说明、参数说明、示例、依赖安装指南
- frontmatter完整,单文件未超过500行
- 提供了清晰的脚本路径定位方法和多Agent安装指南
Highlights
- 提供了脚本路径定位方法、环境自检命令、依赖安装指南
- 覆盖主要异常场景,不可逆操作有确认机制
- 多Agent安装说明详细,确保在不同环境下都能正确执行
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 140, 376, 380, 381, 428 -
Administrator or elevated privileges
Elevate only when necessary. Keep protection and certificate validation enabled and avoid broad system access.
Mentioned in main document · lines 381, 428
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
python3 "$SCRIPT" --check-env
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.