/SKILL.md
使用 python-docx 精确读取、分析、修改 Word 文档(.docx)格式。当用户需要分析文档格式、批量修改格式、统一排版规范、处理中英文混排字体、修改交叉引用样式时使用此 skill。
npx skillsauth add ariyaaditamaputra18/docx-format-skill docx-formatInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
使用 python-docx 库精确操作 Word 文档格式,适用于格式分析、格式规范化、批量修改。
被调用时立即执行:
uv run 执行并检查结果强制性约束:
uv run --with python-docx python3 script.pydoc.paragraphs 和 doc.tables(文档正文常在表格内)qn('w:eastAsia'))python 命令(缺少依赖)触发场景:
触发关键词:修改 Word 格式、统一字体、调整缩进、分析文档格式、参考文献格式
用户需求是什么?
├─ 不清楚当前格式 → 使用 scripts/analyze.py
├─ 应用公文标准 → 使用 scripts/format_official.py
├─ 应用学术标准 → 使用 scripts/format_academic.py
├─ 统一正文格式 → 使用【快速模板:批量格式化】
├─ 修改参考文献 → 使用【快速模板:参考文献处理】
└─ 自定义需求 → 基于【基础模板】组合
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')
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')
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.tablesqn('w:eastAsia') 设置中文字体执行前提醒用户:
执行命令:
uv run --with python-docx python3 script.py
| 错误 | 原因 | 解决方案 |
|------|------|----------|
| 修改未生效 | 遗漏表格内容 | 检查是否处理了 doc.tables |
| 中文字体不对 | 未用 qn('w:eastAsia') | 必须单独设置中文字体 |
| 文件打开失败 | 路径错误或文件被占用 | 检查路径,关闭 Word |
| 依赖缺失 | 未用 uv run | 使用完整命令 |
直接读取 Markdown 文档并按格式要求写入 DOCX,无需 pandoc。
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')
使用预置脚本:
uv run --with python-docx python3 .claude/skills/docx-format/scripts/md_to_docx.py input.md output.docx
font.size 返回 EMU,需转换(÷ 914400 × 72)development
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.
development
Maintainer workflow for OpenClaw releases, prereleases, changelog release notes, and publish validation. Use when Codex needs to prepare or verify stable or beta release steps, align version naming, assemble release notes, check release auth requirements, or validate publish-time commands and artifacts.
development
Run, watch, debug, and extend OpenClaw QA testing with qa-lab and qa-channel. Use when Codex needs to execute the repo-backed QA suite, inspect live QA artifacts, debug failing scenarios, add new QA scenarios, or explain the OpenClaw QA workflow. Prefer the live OpenAI lane with regular openai/gpt-5.4 in fast mode; do not use gpt-5.4-pro or gpt-5.4-mini unless the user explicitly overrides that policy.
development
End-to-end Parallels smoke, upgrade, and rerun workflow for OpenClaw across macOS, Windows, and Linux guests. Use when Codex needs to run, rerun, debug, or interpret VM-based install, onboarding, gateway smoke tests, latest-release-to-main upgrade checks, fresh snapshot retests, or optional Discord roundtrip verification under Parallels.