docx

Create, edit, and validate Word .docx documents and their internal XML structure.

71|10|Updated Mar 7, 2026
One-click install
npx skills add https://github.com/XiaoMaColtAI/BettaFish-skill --skill docx-xiaomacoltai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docx
Source: https://github.com/XiaoMaColtAI/BettaFish-skill/tree/main/subskills/docx
Command: npx skills add https://github.com/XiaoMaColtAI/BettaFish-skill --skill docx-xiaomacoltai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires defusedxml, lxml, and includes scripts (resource) components.

What problem does it solve?

Authors, analysts, and automation engineers often need reliable, repeatable ways to create, edit, and repair Word (.docx) files while preserving formatting, tracked changes, comments, images, and tables of contents; manual XML fiddling or inconsistent toolchains produce corrupted documents and wasted time. This Skill provides deterministic tooling and guidance to generate polished .docx deliverables, safely edit existing documents at the XML level, and validate/repair packaging issues so files open correctly across platforms.

Core Features & Use Cases

  • Create polished .docx: Guidance and patterns for producing Word documents with correct page size, styles, TOC, headers/footers, images, and tables.
  • Edit & preserve redlines: Unpack, merge runs, manage tracked changes/comments, accept or apply changes, and repack without breaking relationships.
  • Validate & repair: XML and relationship validation using XSDs, auto-repair for durableId and whitespace issues, and content-type/reference checks to avoid corrupt DOCX files.
  • Conversion helpers: Integration notes for LibreOffice-based conversions (soffice) for legacy .doc handling and PDF/image generation workflows.
  • Use case example: Automate converting a heavily redlined draft into a clean, publication-ready Word report that includes images, tables, and an auto-generated TOC while preserving audit trails.

Quick Start

Use the docx skill to convert a draft with tracked changes and images into a validated, production-ready .docx with an updated table of contents.

Frequently Asked Questions about docx

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a .docx file with a table of contents, headers, and images?

To create a .docx file with a table of contents, headers, and images, you use generation patterns that define page size, styles, and structural relationships. This ensures formatting and elements are preserved correctly in the final Word document.

What is the best way to edit a Word document with tracked changes without breaking the formatting?

The best way to edit a Word document with tracked changes is to unpack the file, manage XML runs directly, and merge or apply changes before repacking. This preserves formatting and ensures relationships remain intact without corruption.

Can I use LibreOffice to convert legacy .doc files into .docx in an automated workflow?

Yes, you can use LibreOffice (soffice) to convert legacy .doc files into .docx or PDF/image formats. It integrates into automated workflows to handle older document formats before XML validation and packing.

Why does my generated .docx file appear corrupted when opened in Word?

A generated .docx file appears corrupted due to broken XML relationships, invalid content types, or whitespace issues. You resolve this by applying XSD validation and auto-repair checks to fix durableId and reference errors before packing.

Do I need lxml and defusedxml to parse and validate Word document XML?

Yes, you need Python libraries lxml and defusedxml to parse and validate Word document XML. They provide the required XSD validation and secure XML parsing capabilities to safely manage internal document structures.

How do I insert or replace images in an existing .docx file programmatically?

To insert or replace images in an existing .docx file programmatically, you unpack the document, modify the internal XML to update image references, and repack it. This maintains content relationships and prevents packaging errors.