docx

GitHub

处理Microsoft Word .docx文件,支持读取、编辑和创建。涵盖文本结构提取、保留样式的原位编辑及从零生成文档,通过python-docx或OOXML修补实现功能。

src/opensquilla/skills/bundled/docx/SKILL.md opensquilla/opensquilla

Trigger Scenarios

用户提及Word文档或.docx文件 需要提取文档文本或结构 要求修改现有文档内容 根据简报生成新文档 审计修订痕迹

Install

npx skills add opensquilla/opensquilla --skill docx -g -y
More Options

Non-standard path

npx skills add https://github.com/opensquilla/opensquilla/tree/main/src/opensquilla/skills/bundled/docx -g -y

Use without installing

npx skills use opensquilla/opensquilla@docx

指定 Agent (Claude Code)

npx skills add opensquilla/opensquilla --skill docx -a claude-code -g -y

安装 repo 全部 skill

npx skills add opensquilla/opensquilla --all -g -y

预览 repo 内 skill

npx skills add opensquilla/opensquilla --list

SKILL.md

Frontmatter
{
    "name": "docx",
    "homepage": "https:\/\/python-docx.readthedocs.io\/",
    "metadata": {
        "platform": {
            "emoji": "📘",
            "install": [
                {
                    "id": "python-docx",
                    "kind": "uv",
                    "label": "Install python-docx (uv pip)",
                    "package": "python-docx"
                }
            ],
            "requires": {
                "anyBins": [
                    "python",
                    "python3"
                ]
            }
        }
    },
    "entrypoint": {
        "args": [
            "--out",
            "{{ with.output_path }}"
        ],
        "parse": "text",
        "stdin": "{{ with.markdown }}",
        "command": "python {baseDir}\/scripts\/export_markdown_docx.py",
        "timeout": 60
    },
    "provenance": {
        "origin": "clawhub-mit0",
        "license": "MIT-0",
        "upstream_url": "https:\/\/clawhub.ai\/word-docx",
        "maintained_by": "OpenSquilla"
    },
    "description": "Read, edit, or create Microsoft Word `.docx` files. Trigger this skill whenever the user mentions a Word document, .docx file, contract, report, brief, memo, or asks to extract text, modify an existing doc, generate one from a brief, or audit tracked changes. Three execution paths: text-and-structure extraction, in-place edit-by-run (preserves styles), and create-from-scratch with python-docx. Falls back to OOXML unzip-and-patch for layout work python-docx cannot reach."
}

docx

Work with Microsoft Word .docx files. The format is OOXML — a zip container holding XML parts (word/document.xml, styles.xml, numbering.xml, headers, footers, relationships). Treat structure as primary; rendered text is a view.

Decide the path first

Pick one path up front. The right path depends only on what is on disk before you start.

You have Goal Path
Existing .docx Read text/structure A. Inspect
Existing .docx Modify content while keeping styles B. Edit-in-place
Nothing or a brief Build a new doc C. Create from scratch

If the user hands you a doc and asks for changes, default to path B and treat the input as the visual style baseline. Only choose path C when the user says "start fresh" or there is no input.


Path A: Inspect

Dump structure as JSON for inspection without mutating anything.

python {baseDir}/scripts/inspect_docx.py /path/to/doc.docx

Output schema:

{
  "paragraphs": [{"index": 0, "text": "...", "style": "Heading 1"}, ...],
  "tables": [[["row0,col0", "row0,col1"], ...], ...],
  "sections": 1,
  "has_tracked_changes": false
}

Use this whenever you need to see what is in the doc before deciding how to edit. The output is stable and machine-readable — diff two inspect outputs to verify a round-trip preserved everything you intended.


Path B: Edit in place

Two sub-strategies; pick by how invasive the edit is.

B1. Run-level text replacement (preferred)

When the change is "swap this string" or "fill these placeholders": mutate runs in place. This preserves all theme/style/font settings.

python {baseDir}/scripts/edit_docx.py input.docx ops.json --out output.docx

ops.json is a list of operations:

[
  {"op": "replace_run", "para": 0, "run": 0, "text": "Q3 Review"},
  {"op": "replace_text", "find": "{{CLIENT}}", "with": "Acme Corp"}
]

Edit at the run level, not the paragraph level — replacing whole paragraph text drops formatting. If a placeholder spans multiple runs (often happens when the original template applied bold/italic mid-word), the helper script collapses runs into the first one and clears the rest.

B2. Structural edits (sections / page layout / numbering)

python-docx exposes paragraphs, tables, and runs but has limited support for page layout, numbering definitions, and tracked changes. For those, unzip the .docx, patch word/document.xml and adjacent parts, and repack:

mkdir _unpacked && (cd _unpacked && unzip -q ../input.docx)
# edit _unpacked/word/document.xml
(cd _unpacked && zip -q -r ../output.docx . -x "*.DS_Store")

Rules when patching XML:

  • Use defusedxml.ElementTree or lxml, not stdlib xml.etree.ElementTree. ET drops or rewrites namespace prefixes (w:, r:) in ways Word refuses to load.
  • Preserve xml:space="preserve" on <w:t> elements that hold leading or trailing whitespace.
  • [Content_Types].xml must list every part type. Removing a header without also removing its override entry yields a "repair" prompt in Word.
  • Numbering definitions live in numbering.xml; bullet/number changes must patch the numbering ID, not just the visible text.

When done, validate by opening in LibreOffice headless before declaring success — silent failures are common.


Path C: Create from scratch

python {baseDir}/scripts/create_docx.py spec.json --out out.docx

spec.json describes content declaratively:

{
  "metadata": {"title": "Q3 Review", "author": "Wei E."},
  "body": [
    {"kind": "heading", "level": 1, "text": "Q3 Review"},
    {"kind": "paragraph", "text": "Revenue +18% YoY."},
    {"kind": "table", "rows": [["Metric", "Value"], ["Revenue", "$2.1M"]]}
  ]
}

For programmatic use call python-docx directly:

from docx import Document
doc = Document()
doc.add_heading("Q3 Review", level=1)
doc.add_paragraph("Revenue +18% YoY.")
table = doc.add_table(rows=2, cols=2)
table.rows[0].cells[0].text = "Metric"
doc.save("out.docx")

See references/python_docx.md for paragraphs, styles, numbering, tables, headers/footers, and section breaks.


Tracked changes

Tracked changes are stored in word/document.xml as <w:ins> and <w:del> elements. python-docx does not expose them as first-class objects — the inspect helper sets has_tracked_changes: true when any w:ins or w:del element is found, and you must resolve them by patching XML directly. Treat docs with tracked changes as read-only until reviewers accept or reject the revisions.


Common pitfalls

Symptom Cause Fix
Word reports "needs repair" Removed a header part but left override in [Content_Types].xml Strip the override entry too
Text replacement drops bold/italic Replaced paragraph.text instead of editing runs Use op: replace_run
Numbering restarts unexpectedly Edited a list item across two abstractNum definitions Patch numbering.xml; rebuild numbering IDs
Smart-quote characters render as garbage XML read with stdlib ET dropped namespaces Switch to defusedxml or lxml
Long string overflows Cell width is fixed in the template Either shorten or compute auto-fit before save

Boundaries

  • This skill is for .docx (OOXML WordprocessingML). It does not handle .doc (legacy binary) or Google Docs. Convert via LibreOffice or Word export first.
  • Do not run macro-enabled .docm / VBA. The runtime sandbox does not execute embedded code, and security scanners flag mixed content.
  • For PDF generation from a .docx, hand off to LibreOffice headless or a separate PDF skill. This skill stops at .docx.

Version History

  • 7f72a32 Current 2026-07-05 18:38

Same Skill Collection

src/opensquilla/skills/bundled/advanced-dubbing-studio/SKILL.md
src/opensquilla/skills/bundled/ai-video-script/SKILL.md
src/opensquilla/skills/bundled/audio-cog/SKILL.md
src/opensquilla/skills/bundled/awesome-webpage-image-download/SKILL.md
src/opensquilla/skills/bundled/awesome-webpage-research/SKILL.md
src/opensquilla/skills/bundled/AwesomeWebpageMetaSkill/SKILL.md
src/opensquilla/skills/bundled/cron/SKILL.md
src/opensquilla/skills/bundled/filesystem/SKILL.md
src/opensquilla/skills/bundled/git-diff/SKILL.md
src/opensquilla/skills/bundled/github/SKILL.md
src/opensquilla/skills/bundled/history-explorer/SKILL.md
src/opensquilla/skills/bundled/html-coder/SKILL.md
src/opensquilla/skills/bundled/html-to-pdf/SKILL.md
src/opensquilla/skills/bundled/http-fetch/SKILL.md
src/opensquilla/skills/bundled/latex-compile/SKILL.md
src/opensquilla/skills/bundled/memory/SKILL.md
src/opensquilla/skills/bundled/music-and-singing-studio/SKILL.md
src/opensquilla/skills/bundled/nano-banana-pro-openrouter/SKILL.md
src/opensquilla/skills/bundled/nano-banana-pro/SKILL.md
src/opensquilla/skills/bundled/nano-pdf/SKILL.md
src/opensquilla/skills/bundled/openrouter-video-generator/SKILL.md
src/opensquilla/skills/bundled/paper-abstract-author/SKILL.md
src/opensquilla/skills/bundled/paper-citation-planner/SKILL.md
src/opensquilla/skills/bundled/paper-experiment-stub/SKILL.md
src/opensquilla/skills/bundled/paper-outline-author/SKILL.md
src/opensquilla/skills/bundled/paper-preference-planner/SKILL.md
src/opensquilla/skills/bundled/paper-refbib-stub/SKILL.md
src/opensquilla/skills/bundled/paper-revision-author/SKILL.md
src/opensquilla/skills/bundled/paper-section-author/SKILL.md
src/opensquilla/skills/bundled/paper-source-curator/SKILL.md
src/opensquilla/skills/bundled/pptx/SKILL.md
src/opensquilla/skills/bundled/seedance-2-prompt/SKILL.md
src/opensquilla/skills/bundled/skill-creator-linter/SKILL.md
src/opensquilla/skills/bundled/skill-creator-proposals/SKILL.md
src/opensquilla/skills/bundled/skill-creator-smoke-test/SKILL.md
src/opensquilla/skills/bundled/srt-from-script/SKILL.md
src/opensquilla/skills/bundled/stack-trace-generic-probe/SKILL.md
src/opensquilla/skills/bundled/stack-trace-go-probe/SKILL.md
src/opensquilla/skills/bundled/stack-trace-js-probe/SKILL.md
src/opensquilla/skills/bundled/stack-trace-python-probe/SKILL.md
src/opensquilla/skills/bundled/stack-trace-rust-probe/SKILL.md
src/opensquilla/skills/bundled/subtitle-burner/SKILL.md
src/opensquilla/skills/bundled/swe-bench/SKILL.md
src/opensquilla/skills/bundled/text-file-read/SKILL.md
src/opensquilla/skills/bundled/title-card-image/SKILL.md
src/opensquilla/skills/bundled/video-merger/SKILL.md
src/opensquilla/skills/bundled/video-still-animator/SKILL.md
src/opensquilla/skills/bundled/voice-clone-lab/SKILL.md
src/opensquilla/skills/bundled/voice-conversion-studio/SKILL.md
src/opensquilla/skills/bundled/voiceover-studio/SKILL.md
src/opensquilla/skills/bundled/weather/SKILL.md
src/opensquilla/skills/bundled/web-search/SKILL.md
src/opensquilla/skills/bundled/xlsx/SKILL.md
src/opensquilla/skills/exp/meta-arxiv-daily-digest-deck/SKILL.md
src/opensquilla/skills/exp/meta-codereview-current-diff/SKILL.md
src/opensquilla/skills/exp/meta-compliance-audit-bundle/SKILL.md
src/opensquilla/skills/exp/meta-diagram-triangulation/SKILL.md
src/opensquilla/skills/exp/meta-github-pr-watch-digest/SKILL.md
src/opensquilla/skills/exp/meta-issue-to-pr-autopilot/SKILL.md
src/opensquilla/skills/exp/meta-knowledge-base-bootstrap/SKILL.md
src/opensquilla/skills/exp/meta-migration-assistant/SKILL.md
src/opensquilla/skills/exp/meta-multi-format-export-pack/SKILL.md
src/opensquilla/skills/exp/meta-pdf-intelligence/SKILL.md
src/opensquilla/skills/exp/meta-pdf-reformat-pipeline/SKILL.md
src/opensquilla/skills/exp/meta-pre-commit-quality-gate/SKILL.md
src/opensquilla/skills/exp/meta-scheduled-morning-digest/SKILL.md
src/opensquilla/skills/exp/meta-security-review-bundle/SKILL.md
src/opensquilla/skills/exp/meta-spreadsheet-insight/SKILL.md
src/opensquilla/skills/exp/meta-stack-trace-investigator/SKILL.md
src/opensquilla/skills/exp/meta-travel-planner/SKILL.md
src/opensquilla/skills/exp/meta-web-to-pdf-briefing/SKILL.md
tests/_fixtures/meta-paper-write-handwritten.SKILL.md
src/opensquilla/skills/bundled/code-task/SKILL.md
src/opensquilla/skills/bundled/deep-research/SKILL.md
src/opensquilla/skills/bundled/meta-kid-project-planner/SKILL.md
src/opensquilla/skills/bundled/meta-paper-write/SKILL.md
src/opensquilla/skills/bundled/meta-short-drama/SKILL.md
src/opensquilla/skills/bundled/meta-skill-creator/SKILL.md
src/opensquilla/skills/bundled/multi-search-engine/SKILL.md
src/opensquilla/skills/bundled/pdf-toolkit/SKILL.md
src/opensquilla/skills/bundled/skill-creator/SKILL.md
src/opensquilla/skills/bundled/sub-agent/SKILL.md
src/opensquilla/skills/bundled/summarize/SKILL.md
src/opensquilla/skills/bundled/tmux/SKILL.md
src/opensquilla/skills/exp/meta-long-running-build-watchdog/SKILL.md
src/opensquilla/skills/bundled/paper-plot-stub/SKILL.md
src/opensquilla/skills/exp/meta-content-publish-pipeline/SKILL.md
src/opensquilla/skills/exp/meta-home-it-rescue/SKILL.md
src/opensquilla/skills/exp/meta-meeting-to-workflow/SKILL.md
src/opensquilla/skills/exp/meta-research-to-slide-deck/SKILL.md
src/opensquilla/skills/exp/meta-sales-lead-researcher/SKILL.md

Metadata

Files
0
Version
7f72a32
Hash
e595abe8
Indexed
2026-07-05 18:38

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-07-09 07:19
浙ICP备14020137号-1 $bản đồ khách truy cập$