docx

GitHub

提供使用 Python 和 python-docx 库创建、检查和编辑 Word DOCX 文件的指南,涵盖文档结构操作、样式处理及 OOXML 底层修改。

skills/builtin/docx/1.0.0/SKILL.md simplexai-labs/linger

Trigger Scenarios

需要生成或修改 Word 文档 从 DOCX 文件中提取内容

Install

npx skills add simplexai-labs/linger --skill docx -g -y
More Options

Non-standard path

npx skills add https://github.com/simplexai-labs/linger/tree/main/skills/builtin/docx/1.0.0 -g -y

Use without installing

npx skills use simplexai-labs/linger@docx

指定 Agent (Claude Code)

npx skills add simplexai-labs/linger --skill docx -a claude-code -g -y

安装 repo 全部 skill

npx skills add simplexai-labs/linger --all -g -y

预览 repo 内 skill

npx skills add simplexai-labs/linger --list

SKILL.md

Frontmatter
{
    "name": "docx",
    "description": "Create, inspect, or edit Word DOCX files with Python. Use when a Word file is an input or requested deliverable, including templates, tables, comments, and tracked changes."
}

Word documents with Python

Runtime

The active Context has its own Python project in ./agent. Install only the packages needed for the task:

uv --directory ./agent add python-docx

Run Python with uv --directory ./agent run python .... Resolve script, input, and output paths to absolute paths before invoking uv; --directory changes the command's working directory to ./agent. Keep generated scripts and files under the current Context's ./playground/<scope>/ directory. Publish finished files through the available delivery tool; a filesystem path alone is not a Human-accessible deliverable.

Use the Python standard library (zipfile, xml.etree.ElementTree) for package inspection. Add defusedxml if processing untrusted XML with a nonstandard parser. Do not run an install script or use system pip.

Choose the operation

  • Read or extract: Open with python-docx for paragraphs, tables, sections, and document properties. DOCX is an OOXML ZIP; inspect its XML parts when the high-level view omits headers, footers, comments, text boxes, or revisions. Keep the original order of paragraphs and tables when order matters.
  • Create: Use python-docx. Set page size and margins, named styles, fonts, and table widths deliberately. Put repeated formatting in styles. For CJK text, check that the chosen font covers the characters actually used.
  • Edit an existing file: Work on a copy. Change the relevant paragraphs, runs, tables, or sections while preserving the template's styles, headers, footers, and unrelated package parts. Avoid replacing an entire paragraph when its runs carry meaningful formatting or links.
  • Comments or tracked changes: Inspect existing OOXML first. Use a narrowly scoped OOXML edit only when the installed python-docx API cannot express the requested change. Preserve relationships and IDs, and do not accept or discard revisions without a request to do so. Set comment and revision author from the user's instructions or a neutral descriptive value; never stamp a vendor identity.

Example: preserve an existing document while changing one run

from docx import Document

source = "/absolute/path/input.docx"
target = "/absolute/path/output.docx"
doc = Document(source)
for paragraph in doc.paragraphs:
    for run in paragraph.runs:
        if "Old term" in run.text:
            run.text = run.text.replace("Old term", "New term")
doc.save(target)

This example handles text wholly inside one run. If a match spans runs, map the text back to runs and preserve their formatting; do not flatten the paragraph as a shortcut.

Check the result

Reopen the saved DOCX with python-docx; compare expected text, tables, sections, and document properties with the request. Check ZIP integrity with zipfile.ZipFile(...).testzip(). For layout-sensitive work, render with an available Word-compatible viewer and inspect every page. The Runtime does not include LibreOffice by default; if no renderer is available, report that visual layout was not checked.

Version History

  • d8ebc34 Current 2026-11-14 00:25

Same Skill Collection

skills/builtin/canvas/1.0.0/SKILL.md
skills/builtin/canvas/1.0.1/SKILL.md
skills/builtin/canvas/1.0.2/SKILL.md
skills/builtin/collaborate/1.0.0/SKILL.md
skills/builtin/create-meeting-minutes/1.0.0/SKILL.md
skills/builtin/holistic-context/1.0.0/SKILL.md
skills/builtin/humanlike-browse/1.0.0/SKILL.md
skills/builtin/humanlike-browse/1.0.1/SKILL.md
skills/builtin/humanlike-browse/1.0.2/SKILL.md
skills/builtin/humanlike-browse/1.0.3/SKILL.md
skills/builtin/humanlike-browse/1.0.4/SKILL.md
skills/builtin/humanlike-browse/1.0.8/SKILL.md
skills/builtin/impeccable/1.0.0/SKILL.md
skills/builtin/impeccable/1.0.1/SKILL.md
skills/builtin/lev8-search/1.0.0/SKILL.md
skills/builtin/lev8-search/1.0.1/SKILL.md
skills/builtin/media-generation/1.0.3/SKILL.md
skills/builtin/pdf/1.0.0/SKILL.md
skills/builtin/pptx/1.0.0/SKILL.md
skills/builtin/pptx/1.0.1/SKILL.md
skills/builtin/pptx/1.0.2/SKILL.md
skills/builtin/proactive-response/1.0.0/SKILL.md
skills/builtin/proactive-response/1.0.1/SKILL.md
skills/builtin/skill-installer/1.0.0/SKILL.md
skills/builtin/slide-deck/1.0.0/SKILL.md
skills/builtin/slide-deck/1.0.1/SKILL.md
skills/builtin/superpowers/1.0.0/SKILL.md
skills/builtin/taste/1.0.0/SKILL.md
skills/builtin/taste/1.0.1/SKILL.md
skills/builtin/teamhub-files/1.0.0/SKILL.md
skills/builtin/teamhub-files/1.0.1/SKILL.md
skills/builtin/teamhub-files/1.0.2/SKILL.md
skills/builtin/teamhub-files/1.0.3/SKILL.md
skills/builtin/xlsx/1.0.0/SKILL.md
skills/builtin/artifact/1.0.0/SKILL.md
skills/builtin/artifact/1.0.1/SKILL.md
skills/builtin/artifact/1.0.2/SKILL.md
skills/builtin/chat-card/1.0.0/SKILL.md
skills/builtin/personal-profile/1.0.0/SKILL.md
skills/builtin/personal-profile/1.0.1/SKILL.md
skills/builtin/personal-profile/1.0.2/SKILL.md
skills/builtin/personal-profile/1.0.3/SKILL.md
skills/builtin/personal-profile/1.0.4/SKILL.md
skills/builtin/personal-profile/1.0.5/SKILL.md

Metadata

Files
0
Version
d8ebc34
Hash
da5bb3c5
Indexed
2026-11-14 00:25

ホーム - Wiki
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-11-14 07:27
浙ICP备14020137号-1