docx
Work with Microsoft Word `.docx` files using the installed `paper-docx` distribution, which imports as `docx` and extends `python-docx` with inspection, guarded edits, review structures, composition, diffs, and byte-preserving saves.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 237
- Forks
- 24
01 前言 Front Matter
- name
- docx
- description
- Work with Microsoft Word `.docx` files using the installed `paper-docx` distribution, which imports as `docx` and extends `python-docx` with inspection, guarded edits, review structures, composition, diffs, and byte-preserving saves.
02 资源文件 107
- 参考文档references/api/api.md502 B
- 参考文档references/api/blkcntnr.md1.7 KB
- 参考文档references/api/blocks.md4.9 KB
- 参考文档references/api/bookmarks.md2.5 KB
- 参考文档references/api/commentops.md4.5 KB
- 参考文档references/api/comments.md3.3 KB
- 参考文档references/api/composition.md4.3 KB
- 参考文档references/api/controls.md3.1 KB
- 参考文档references/api/dml.color.md2.1 KB
- 参考文档references/api/document.md5.6 KB
- 参考文档references/api/drawing.md1.8 KB
- 参考文档references/api/enum.base.md1.5 KB
- 参考文档references/api/enum.dml.md3.6 KB
- 参考文档references/api/enum.section.md2.6 KB
- 参考文档references/api/enum.shape.md667 B
- 参考文档references/api/enum.style.md12.7 KB
- 参考文档references/api/enum.table.md3.9 KB
- 参考文档references/api/enum.text.md11.0 KB
- 参考文档references/api/errors.md2.8 KB
- 参考文档references/api/exceptions.md512 B
- 参考文档references/api/fields.md2.5 KB
- 参考文档references/api/formatting.md1.7 KB
- 参考文档references/api/image.bmp.md571 B
- 参考文档references/api/image.constants.md4.5 KB
- 参考文档references/api/image.exceptions.md502 B
- 参考文档references/api/image.gif.md688 B
- 参考文档references/api/image.helpers.md1.6 KB
- 参考文档references/api/image.image.md4.0 KB
- 参考文档references/api/image.jpeg.md913 B
- 参考文档references/api/image.md400 B
- 参考文档references/api/image.png.md565 B
- 参考文档references/api/image.tiff.md629 B
- 参考文档references/api/index.md58.4 KB
- 参考文档references/api/links.md1.1 KB
- 参考文档references/api/notes.md1.4 KB
- 参考文档references/api/numbering.md3.9 KB
- 参考文档references/api/opc.constants.md21.0 KB
- 参考文档references/api/opc.coreprops.md1017 B
- 参考文档references/api/opc.exceptions.md344 B
- 参考文档references/api/opc.oxml.md5.0 KB
- 参考文档references/api/opc.package.md4.1 KB
- 参考文档references/api/opc.packuri.md2.0 KB
- 参考文档references/api/opc.part.md4.9 KB
- 参考文档references/api/opc.parts.coreprops.md772 B
- 参考文档references/api/opc.phys_pkg.md1.2 KB
- 参考文档references/api/opc.pkgreader.md1.5 KB
- 参考文档references/api/opc.pkgwriter.md620 B
- 参考文档references/api/opc.rel.md1.4 KB
- 参考文档references/api/opc.shared.md647 B
- 参考文档references/api/opc.spec.md674 B
- 参考文档references/api/oxml.comments.md2.5 KB
- 参考文档references/api/oxml.coreprops.md3.0 KB
- 参考文档references/api/oxml.document.md2.4 KB
- 参考文档references/api/oxml.drawing.md326 B
- 参考文档references/api/oxml.exceptions.md378 B
- 参考文档references/api/oxml.ns.md2.9 KB
- 参考文档references/api/oxml.numbering.md2.4 KB
- 参考文档references/api/oxml.parser.md1.7 KB
- 参考文档references/api/oxml.revision.md1.3 KB
- 参考文档references/api/oxml.section.md7.8 KB
- 参考文档references/api/oxml.settings.md664 B
- 参考文档references/api/oxml.shape.md4.9 KB
- 参考文档references/api/oxml.shared.md1.3 KB
- 参考文档references/api/oxml.simpletypes.md5.9 KB
- 参考文档references/api/oxml.styles.md6.0 KB
- 参考文档references/api/oxml.table.md11.3 KB
- 参考文档references/api/oxml.text.font.md5.9 KB
- 参考文档references/api/oxml.text.hyperlink.md995 B
- 参考文档references/api/oxml.text.pagebreak.md2.3 KB
- 参考文档references/api/oxml.text.paragraph.md2.0 KB
- 参考文档references/api/oxml.text.parfmt.md5.4 KB
- 参考文档references/api/oxml.text.run.md4.1 KB
- 参考文档references/api/oxml.xmlchemy.md4.7 KB
- 参考文档references/api/package.md9.0 KB
- 参考文档references/api/parts.comments.md640 B
- 参考文档references/api/parts.document.md2.9 KB
- 参考文档references/api/parts.endnotes.md501 B
- 参考文档references/api/parts.footnotes.md509 B
- 参考文档references/api/parts.hdrftr.md468 B
- 参考文档references/api/parts.image.md1.5 KB
- 参考文档references/api/parts.numbering.md637 B
- 参考文档references/api/parts.settings.md706 B
- 参考文档references/api/parts.story.md2.2 KB
- 参考文档references/api/parts.styles.md574 B
- 参考文档references/api/protection.md2.9 KB
- 参考文档references/api/revision.md3.8 KB
- 参考文档references/api/search.md8.4 KB
- 参考文档references/api/section.md5.3 KB
- 参考文档references/api/settings.md610 B
- 参考文档references/api/shape.md884 B
- 参考文档references/api/shared.md6.5 KB
- 参考文档references/api/story.md4.4 KB
- 参考文档references/api/styles.latent.md2.1 KB
- 参考文档references/api/styles.md1.2 KB
- 参考文档references/api/styles.style.md4.0 KB
- 参考文档references/api/styles.styles.md1.8 KB
- 参考文档references/api/table.md3.0 KB
- 参考文档references/api/tableops.md2.5 KB
- 参考文档references/api/text.font.md6.0 KB
- 参考文档references/api/text.hyperlink.md3.9 KB
- 参考文档references/api/text.pagebreak.md3.8 KB
- 参考文档references/api/text.paragraph.md4.0 KB
- 参考文档references/api/text.parfmt.md4.3 KB
- 参考文档references/api/text.run.md6.5 KB
- 参考文档references/api/text.tabstops.md1.9 KB
- 参考文档references/api/types.md701 B
- 参考文档references/paper-api.md12.5 KB
03 SKILL.md 正文
DOCX with paper-docx
paper-docx is an upgraded distribution of python-docx. It keeps the familiar import and ordinary API:
from docx import Document
document = Document(source_path)
Use your existing knowledge of python-docx for normal paragraphs, runs, styles, tables, sections, pictures, headers, and footers. The fork adds public APIs where ordinary python-docx is weak: finding text across fragmented runs and document stories, editing revisions and review structures, targeting bookmarks/fields/content controls, composing documents, inspecting package changes, and refusing operations it cannot perform safely.
paper-docx is installed under the docx import.
The Paper API companion maps Paper-specific capabilities to their public symbols. The generated API reference covers the complete public API, including the surface inherited from python-docx, with one page per module. It is large; search by symbol and read only the relevant section.
Package behavior
Paper's targets are live. A successful text-changing replacement consumes its Span or Block; an Anchor is location evidence rather than a mutation target. Contextual ranking is inspection-only.
Opening a document can refuse. paper-docx validates the package on intake and rejects an archive with more than one reading, so a hand-rezipped or tool-mangled file may raise MalformedPackageError where upstream python-docx opened it. Saving applies the same check to its own output. Report the refusal and its message rather than working around it; each such refusal matches what Word itself does with that file. Use docx.package.diagnose(path) to triage a file before opening it, since it reports rather than raises.
A docx.errors.PaperRefusal means paper-docx cannot guarantee the attempted operation through its guarded API. The concrete subclass and message identify the condition that caused the refusal; DocumentProtectedError has a documented override in acknowledge_protection(document). In rare cases an ordinary python-docx mutation or direct package editing may be appropriate when unguarded serialization is intentionally acceptable and its effects on the document's package and its revision, comment, and numbering structures are understood. Verify the resulting document carefully; the intake refusal above is not covered.
Precise ZIP/OOXML work is still available when it is genuinely the narrowest operation, the exact package member and schema are understood, and the edit does not cross an ownership boundary that Paper is protecting. Work on a separate candidate, preserve the source, and keep the changed-member budget explicit.
Saving
Document.save() uses ordinary serialization. docx.package.patch_save() retains the original bytes of unchanged package parts and returns change evidence.
04 同仓库更多 Skills
xlsx
Work with Excel `.xlsx` and `.xlsm` files using the installed `paper-xlsx` distribution, which imports as `openpyxl` and extends it with preservation-aware saves, guarded structural edits, recalculation helpers, diffs, and richer inspection.
pptx
Work with Microsoft PowerPoint `.pptx` files using the installed `paper-pptx` distribution, which imports as `pptx` and extends `python-pptx` with inspection, guarded edits, composition, diffs, and package-preserving saves.
Work with PDF files using the installed tools for fixed-page authoring, extraction, page operations, forms, annotations, redactions, and mechanical checks.
generate-greeting
Generate a greeting message and write it to a file.