Skills Plugins MCP Prompt Model 博客 我的中心

docx-format

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

DeepseekModel Curated skill Quality Good · 64 v1.0.0

Get

https://deepseekmodel.com/api/download.php?id=ninestep-docx-format-skill-skill-md&format=skill
Download .skill Standard format with system_prompt and model_config, ready for any agent framework
The actual content of the system_prompt field in the .skill file.
name docx-format description 使用 python-docx 精确读取、分析、修改 Word 文档(.docx)格式。当用户需要分析文档格式、批量修改格式、统一排版规范、处理中英文混排字体、修改交叉引用样式时使用此 skill。 Word 文档格式处理 使用 python-docx 库精确操作 Word 文档格式,适用于格式分析、格式规范化、批量修改。 核心规则 被调用时立即执行 : 确认文件路径 :询问用户 Word 文档的完整路径 明确需求 :确认是分析格式还是修改格式,目标规范是什么 选择模板 :根据需求选择合适的代码模板或脚本 生成脚本 :创建独立的 Python 脚本文件 执行验证 :使用 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 ├─ 统一正文格式 → 使用【快速模板:批量格式化】 ├─ 修改参考文献 → 使用【快速模板:参考文献处理】 └─ 自定义需求 → 基于【基础模板】组合 快速开始 基础模板 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.tables 使用 qn('w:eastAsia') 设置中文字体 正确的输入/输出文件路径 执行前提醒用户 : 备份原文件或使用不同的输出文件名 确认文件未被其他程序打开 执行命令 : 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。 基础模板 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 注意事项 只支持 .docx :不支持旧版 .doc 表格内容 :学术论文、报告等正文常在表格内,必须处理 单位转换 : font.size 返回 EMU,需转换(÷ 914400 × 72) 备份原文件 :修改前建议备份 Markdown 转换 :使用 pandoc 转换后再格式化
Keywords that activate this skill. Click one to copy it.

This skill does not provide trigger words.

The downloaded .skill package contains the following fields.
Field Description
formatFormat tag (skill/v1)
skill_idUnique skill ID
nameSkill name
versionVersion
descriptionDescription
categoryCategories (array)
trigger_wordsTrigger words
tagsTags
sourceSource
source_urlSource URL (this page)
exported_atExported at (set per download)
system_promptSystem prompt body
model_configModel config: provider / model / temperature / max_tokens / top_p
examplesExamples
install_guideImport guide for Coze / Dify / Claude / custom frameworks
The same skill can be exported in different platform formats.
.skill Standard format with system_prompt and model_config, ready for any agent framework Download
.skillpro Enhanced format with scripts, tools, dependencies and hooks Download
.json Plain JSON export with system_prompt and model parameters only Download
Coze Markdown with frontmatter, for Coze platform import Download
Dify Dify DSL, import directly after creating an app Download

每日精选 Skill 推荐,免费送到你邮箱

输入邮箱,每天接收一个精选 AI Agent 技能推荐。完全免费,持续更新。

验证码 --

提交后我们会发送一封确认邮件,点击邮件里的链接才会开始收信。

完全免费,取消任意时间。我们不会发送垃圾邮件。