Docx Format logo

Docx Format

Community
ninestep
docx-format

使用 python-docx 精确读取、分析、修改 Word 文档(.docx)格式。当用户需要分析文档格式、批量修改格式、统一排版规范、处理中英文混排字体、修改交叉引用样式时使用此 skill。

Overview

Publisherninestep
Repositorydocx-format-skill
Skill namedocx-format
Stars
51
Forks
1
Bundled files
6
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 6 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by ninestep on GitHub. Read the source before you install it.

Installation

Install the Docx Format AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/ninestep/docx-format-skill/tree/main
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ninestep/docx-format-skill.git \
  .claude/skills/docx-format
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Docx Format in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Docx Format on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Docx Format is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Word 文档格式处理

使用 python-docx 库精确操作 Word 文档格式,适用于格式分析、格式规范化、批量修改。

核心规则

被调用时立即执行:

  1. 确认文件路径:询问用户 Word 文档的完整路径
  2. 明确需求:确认是分析格式还是修改格式,目标规范是什么
  3. 选择模板:根据需求选择合适的代码模板或脚本
  4. 生成脚本:创建独立的 Python 脚本文件
  5. 执行验证:使用 uv run 执行并检查结果

强制性约束:

  • ✓ 必须使用 uv run --with python-docx python3 script.py
  • ✓ 必须处理 doc.paragraphs 和 doc.tables(文档正文常在表格内)
  • ✓ 必须分设 中英文字体(使用 qn('w:eastAsia'))
  • ✓ 必须询问 用户文件路径和输出路径
  • ✗ 禁止使用 直接 python 命令(缺少依赖)
  • ✗ 禁止遗漏 表格内容处理(常见错误)

何时使用

触发场景:

  • 分析 Word 文档格式(字体/字号/缩进/行距)
  • 批量修改文档格式
  • 统一排版规范(学术论文、报告等)
  • 处理中英文混排字体
  • 修改交叉引用/参考文献样式

触发关键词:修改 Word 格式、统一字体、调整缩进、分析文档格式、参考文献格式

决策树

用户需求是什么?
├─ 不清楚当前格式 → 使用 scripts/analyze.py
├─ 应用公文标准 → 使用 scripts/format_official.py
├─ 应用学术标准 → 使用 scripts/format_academic.py
├─ 统一正文格式 → 使用【快速模板:批量格式化】
├─ 修改参考文献 → 使用【快速模板:参考文献处理】
└─ 自定义需求 → 基于【基础模板】组合

快速开始

基础模板

python
from docx import Document
from docx.shared import Pt
from docx.oxml.ns import qn

doc = Document('input.docx')

def set_font(run, cn='宋体', en='Times New Roman', size=10.5):
    """设置中英文字体"""
    run.font.name = en
    run._element.rPr.rFonts.set(qn('w:eastAsia'), cn)
    run.font.size = Pt(size)

def process_all_paragraphs(doc, process_func):
    """遍历所有段落(包括表格内)"""
    for para in doc.paragraphs:
        process_func(para)

    for table in doc.tables:
        for row in table.rows:
            for cell in row.cells:
                for para in cell.paragraphs:
                    process_func(para)

# 使用示例
def format_para(para):
    para.paragraph_format.first_line_indent = Pt(21)
    for run in para.runs:
        set_font(run, cn='宋体', en='Times New Roman', size=10.5)

process_all_paragraphs(doc, format_para)
doc.save('output.docx')

快速模板:批量格式化

python
from docx import Document
from docx.shared import Pt
from docx.oxml.ns import qn

doc = Document('input.docx')

for para in doc.paragraphs:
    if len(para.text.strip()) > 30:
        para.paragraph_format.first_line_indent = Pt(21)
        para.paragraph_format.line_spacing = 1.5
        for run in para.runs:
            run.font.name = 'Times New Roman'
            run._element.rPr.rFonts.set(qn('w:eastAsia'), '宋体')
            run.font.size = Pt(10.5)

for table in doc.tables:
    for row in table.rows:
        for cell in row.cells:
            for para in cell.paragraphs:
                if len(para.text.strip()) > 30:
                    para.paragraph_format.first_line_indent = Pt(21)
                    for run in para.runs:
                        run.font.name = 'Times New Roman'
                        run._element.rPr.rFonts.set(qn('w:eastAsia'), '宋体')
                        run.font.size = Pt(10.5)

doc.save('output.docx')

快速模板:参考文献处理

python
from docx import Document
from docx.shared import Pt, RGBColor
import re

doc = Document('input.docx')
ref_pattern = re.compile(r'\[\d+\]')

for para in doc.paragraphs:
    if para.text.strip().startswith('[') and ']' in para.text[:5]:
        para.paragraph_format.first_line_indent = Pt(-21)
        para.paragraph_format.left_indent = Pt(21)

    for run in para.runs:
        if ref_pattern.search(run.text):
            run.font.color.rgb = RGBColor(0, 0, 255)

doc.save('output.docx')

执行检查清单

生成脚本前:

  • 已确认用户提供的文件路径
  • 已明确目标格式规范
  • 已选择合适的模板或脚本

脚本中必须包含:

  • 同时处理 doc.paragraphs 和 doc.tables
  • 使用 qn('w:eastAsia') 设置中文字体
  • 正确的输入/输出文件路径

执行前提醒用户:

  • 备份原文件或使用不同的输出文件名
  • 确认文件未被其他程序打开

执行命令:

bash
uv run --with python-docx python3 script.py

常见错误

错误原因解决方案
修改未生效遗漏表格内容检查是否处理了 doc.tables
中文字体不对未用 qn('w:eastAsia')必须单独设置中文字体
文件打开失败路径错误或文件被占用检查路径,关闭 Word
依赖缺失未用 uv run使用完整命令

相关文档

  • STANDARDS.md - 默认格式标准(公文/学术论文)和参数速查表
  • EXAMPLES.md - 详细示例代码(多级标题、表格、图片、页眉页脚等)
  • scripts/ - 预置工具脚本(分析、公文格式化、学术格式化)

Markdown 转 DOCX

直接读取 Markdown 文档并按格式要求写入 DOCX,无需 pandoc。

基础模板

python
from docx import Document
from docx.shared import Pt
from docx.oxml.ns import qn
from docx.enum.text import WD_ALIGN_PARAGRAPH
import re

doc = Document()

def add_heading(doc, text, level):
    """添加标题"""
    para = doc.add_paragraph(text)
    if level == 1:
        para.alignment = WD_ALIGN_PARAGRAPH.CENTER
        for run in para.runs:
            run.font.name = 'Arial'
            run._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
            run.font.size = Pt(15)
            run.font.bold = True
    elif level == 2:
        para.alignment = WD_ALIGN_PARAGRAPH.LEFT
        for run in para.runs:
            run.font.name = 'Arial'
            run._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
            run.font.size = Pt(14)
            run.font.bold = True
    elif level == 3:
        para.alignment = WD_ALIGN_PARAGRAPH.LEFT
        for run in para.runs:
            run.font.name = 'Arial'
            run._element.rPr.rFonts.set(qn('w:eastAsia'), '黑体')
            run.font.size = Pt(12)
            run.font.bold = True

def add_paragraph(doc, text):
    """添加正文段落"""
    para = doc.add_paragraph(text)
    para.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
    para.paragraph_format.first_line_indent = Pt(24)
    para.paragraph_format.line_spacing = 1.5
    for run in para.runs:
        run.font.name = 'Times New Roman'
        run._element.rPr.rFonts.set(qn('w:eastAsia'), '宋体')
        run.font.size = Pt(12)

# 读取 Markdown
with open('input.md', 'r', encoding='utf-8') as f:
    for line in f:
        line = line.rstrip()
        if not line:
            continue

        # 标题
        if line.startswith('# '):
            add_heading(doc, line[2:], 1)
        elif line.startswith('## '):
            add_heading(doc, line[3:], 2)
        elif line.startswith('### '):
            add_heading(doc, line[4:], 3)
        # 正文
        else:
            add_paragraph(doc, line)

doc.save('output.docx')

使用预置脚本:

bash
uv run --with python-docx python3 .claude/skills/docx-format/scripts/md_to_docx.py input.md output.docx

注意事项

  1. 只支持 .docx:不支持旧版 .doc
  2. 表格内容:学术论文、报告等正文常在表格内,必须处理
  3. 单位转换:font.size 返回 EMU,需转换(÷ 914400 × 72)
  4. 备份原文件:修改前建议备份
  5. Markdown 转换:使用 pandoc 转换后再格式化

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Docx Format AI skill do?

使用 python-docx 精确读取、分析、修改 Word 文档(.docx)格式。当用户需要分析文档格式、批量修改格式、统一排版规范、处理中英文混排字体、修改交叉引用样式时使用此 skill。

Why use Docx Format on TypingMind?

Because you install it once and use it with any model. Docx Format is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Docx Format in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/ninestep/docx-format-skill/tree/main. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Docx Format?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Docx Format?

As many as you like. As long as a model supports skills, you can use Docx Format with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Docx Format AI skill free?

It is published on GitHub by ninestep. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇