当前位置: 首页 > Skill >

docx优化版

docx优化版

docx优化版

A complete, runnable toolkit for working with Word documents. It treats a .docx as what it really is — a ZIP of XML parts — and edits only the bytes you ask for. That unpack → edit XML in place → repack approach is the core idea: it guarantees zero format loss, preserving styles, themes, headers/footers, multi-section layouts, numbering, track-changes, fields and embedded images that full regeneration would destroy. python-docx is used for clean creation; LibreOffice + poppler give faithful PDF/

2026.11.14 583
获取Skill文件查看使用说明
作 者:沈辰 许可证: 更新时间:2026.11.14
本文目录收起

DOCX Skill

A complete, runnable toolkit for working with Word documents. It treats a .docx as what it really is — a ZIP of XML parts — and edits only the bytes you ask for. That unpack → edit XML in place → repack approach is the core idea: it guarantees zero format loss, preserving styles, themes, headers/footers, multi-section layouts, numbering, track-changes, fields and embedded images that full regeneration would destroy. python-docx is used for clean creation; LibreOffice + poppler give faithful PDF/PNG rendering so you can actually look at the result.

Designed to work reliably in Chinese / CJK contexts: UTF-8 throughout, run-aware find/replace, East-Asian font handling, the 字号 size table, and GB/T 9704 公文 layout guidance.

Quick Start

# 0. once per session
python3 scripts/docx_doctor.py            # -> READY

# 1. READ
python3 scripts/docx_reader.py in.docx --outline

# 2. ACT (edit existing)
python3 scripts/docx_unpack.py in.docx /tmp/wd
python3 scripts/docx_replace_text.py /tmp/wd --find OLD --replace NEW
python3 scripts/docx_pack.py /tmp/wd out.docx

# 3. VERIFY
python3 scripts/docx_validate.py out.docx --report
python3 scripts/docx_reader.py out.docx --diff-against in.docx
python3 scripts/docx_render.py out.docx --out /tmp/rev      # LOOK at the PNG

Full walkthrough: references/quickstart.md.

Task routing

Decide the pipeline by asking "is there an input .docx?" — details and a flowchart in references/decision-guide.md.

Pipeline When Read
A — CREATE No input file; write a new document references/create.md
B — FILL-EDIT Have a .docx; replace/fill/add content references/edit.md
C — FORMAT-APPLY Restyle or apply a template references/format.md

C has two strategies: C-1 Overlay (template is pure style) and C-2 Base-Replace (template carries structure). See format.md.

The non-negotiable workflow: READ → ACT → VERIFY

  1. READ with docx_reader.py before touching anything.
  2. ACT by editing the unpacked XML (or building with python-docx).
  3. VERIFY — every output must pass:
    • docx_validate.py (element-order gate, exit 0), and
    • docx_reader.py --diff-against (changed only what you intended), and
    • docx_render.py (LOOK at the rendered PNG — layout/fonts/overflow). Never deliver a file you have not validated and rendered.

Critical rules (full detail in references)

  • Element order (validate.md, openxml-element-order.md): w:pPr first in w:p; w:rPr first in w:r; w:tcPr first and ≥1 w:p in w:tc; w:sectPr LAST in w:body. Insert trailing content before the body sectPr.
  • Headings need w:outlineLvl (H1→0, H2→1, H3→2) or they vanish from the TOC / navigation pane.
  • Track changes: w:ins holds w:t; w:del holds w:delText.
  • Units (openxml-units.md): font w:sz = points×2 (half-points); lengths in dxa/twips (1in=1440, 1cm≈567); images in EMU (1cm=360000).
  • CJK (cjk-guide.md): set w:rFonts w:eastAsia; use the 字号 table; for 公文 follow GB/T 9704 (仿宋_GB2312 三号 body, 黑体 headings). LibreOffice substitutes missing Chinese fonts with Noto for rendering — the stored font name stays correct.
  • Prefer editing over regenerating — it is the only way to keep zero format loss.

Scripts (scripts/)

Script Purpose
docx_doctor.py Environment self-check (deps, soffice, poppler, CJK fonts)
docx_reader.py Overview / --outline / --preview / --diff-against
docx_unpack.py Unzip .docx → working dir
docx_pack.py Repack working dir → .docx
docx_replace_text.py Run-aware find/replace (--regex, --parts all)
docx_fill_placeholders.py Fill template placeholders from JSON
docx_add_paragraph.py Insert paragraph/heading (--style,--outline,--after-text)
docx_merge_runs.py Consolidate fragmented same-format runs
docx_validate.py Element-order / content gate-check (exit 0/1)
docx_render.py Render to PDF + per-page PNG
libreoffice_convert.py Convert .doc/.odt/.rtf→.docx, or →PDF
_docx_common.py Shared XML helpers (import, not a CLI)

References (references/)

quickstart.md · decision-guide.md · read-analyze.md · create.md · edit.md · format.md · validate.md · visual-review.md · cjk-guide.md · openxml-element-order.md · openxml-units.md · troubleshooting.md

Templates (templates/)

minimal_docx/ — a minimal valid unpacked package you can copy, edit and pack as a starting point.

相关文章

更多
Python自动化处理Word文档:批量修正题库格式

利用Python的python-docx库,可自动化解决Word题库文档中常见的格式混乱问题。通过遍历段落并识别特定模式,程序能精准删除多余数字行、空白行及无关页眉页脚文字,同时修正错误的题目序号并将分散的选项合并至同一行,从而高效完成文档重新排版。

2025.12.03 520
Skill 文件
  • SKILL.md
    • DOCX Skill
    • Quick Start
    • Task routing
    • The non-negotiable workflow: READ → ACT → VERIFY
    • Critical rules (full detail in references)
    • Scripts (scripts/)
    • References (references/)
    • Templates (templates/)

相关 Skill

更多
员工手册智囊 员工手册智囊 员工手册智囊(Smart Handbook)是一款由广东知恒(大连)律师事务所高圣杰律师(V:gsj15940877933)开发的面向律师、企业法务及 HR 的专业员工手册合规审查与起草工具,覆盖审核、起草、修订、版本比对四条核心流程,支持通用/互联网/科创/制造业四大行业模板。【核心能力】:全量审查 + 增量截图双模式;基于 python-docx 的落痕回写,修改建议直接写入原 Word 文档并保留 Track Changes 修订痕迹,可回溯每条修改的来龙去脉。降级分流三通道:IMA 知识库未连接时自动降级为本地法律法规库审查;北大法宝未开通则跳过时效核验仅做本地规则匹配;关联 Skill(绩效智囊/合同智囊)未安装则跳过交叉 QC 门不阻塞主流程。协议锁五步:强制加载引用文件 → IMA 七库知识库订阅核验 → 本地 13 部法律基准逐条比对 → 15 类风险模式兜底扫描 → 全国各省市地域差异专项标注。确保每次审查输出可控可追溯:【满血版/标准版】双轨;定稿后迭代判断采用"原条款→问题标注→简版示范+全版示范"三段式落痕逻辑,审核报告按风险等级(🔴致命/🟠严重/🟡一般/⚪提示
合同法务助手 合同法务助手 <h2>合同审查与起草技能 V1.0</h2> <h2>核心特性</h2> <ol> <li>本地资源优先:强制调用本地合同模板、法规、审查规则,无资源时自动兜底</li> <li>全维度审查:错字/标点/专业用词/法律风险一站式检查</li> <li>一体化服务:起草→审查→修订→Word导出全流程</li> <li>溯源可查:所有操作自动记录日志</li> <li>纯Python实现:仅需python-docx,无Node/JS环境依赖</li> </ol> <h2>触发指令</h2> <ul> <li>审查合同/合同审查:启动全维度合同审查</li> <li>起草合同/生成合同:按本地模板生成标准化合同</li> <li>导出合同审查修订版/创建Word版合同:导出审查报告+修订版合同</li> <li>查看本地合同模板/查看本地法规库:展示本地资源</li> </ul> <h2>导出文件</h2> <ul> <li>合同审查报告.docx:问题清单、修改建议、法规依据</li> <li>合同修订版.docx:带修改痕迹的标准化合同文本</li> </ul>
文档工具箱免费版 文档工具箱免费版 使用python-docx读写与编辑DOCX文档,支持基础格式化与视觉校验,适合日常文档处理。
8D Report Generator(智能8D报告) 8D Report Generator(智能8D报告) 8D Report Generator 是一款专为制造业质量管理智能8D问题解决报告生成器,面向制造业质量管理与QE品质异常场景。用户只需描述品质问题或者描述一段品质异常事情,AI即逐阶段(D0-D8)引导访谈、动态生成建议,最终输出专业Word(.docx)格式8D报告,覆盖客户投诉、供应商异常、内部品质整改等全流程。 🎯 核心能力: 1. 场景锚定 — AI自动推断行业维度、问题类型、严重度与角色,确保每个阶段的建议都贴合实际场景 2. 交互式访谈 — 逐阶段(D0-D8)引导用户回答关键问题,每轮提供2-3条可直接采纳的动态建议 3. 质量门控 — 每阶段完成后自动校验信息完整性,确保报告数据无遗漏 4. 根因分析 — 内置5-Why推理链、鱼骨图(Fishbone)、Is-Is Not分析法 5. 专业输出 — 基于python-docx动态生成Word(.docx)格式报告,格式符合SQE客户回复标准 📋 典型流程: 用户输入"客户投诉MA1555线缆标签破损" → AI从D0开始逐阶段提问 → 用户可用「用建议」一键采纳 → 各阶段完成后→ 自动生成完整8D报告 🏭
商务文档专业排版 商务文档专业排版 通用商务文档一键专业排版。当用户需要把粗粝的 Markdown / 纯文本 / 草稿 docx 排版成专业商务 Word 文档时使用。自动应用 v5 专业排版规范(深蓝表头 #1F4E79 + 白字高对比、斑马纹表格、外粗内细边框、微软雅黑),支持封面页、多级标题层级、正文段落格式化、表格美化、页眉页脚。纯 Python 本地实现(python-docx),无需 API Key 或云服务。触发词包括"排版""美化Word""专业文档""商务排版""docx排版""文档美化""生成报告"等。