Docx
Overview
This skill enables comprehensive Word document operations through multiple specialized workflows for reading, creating, and editing documents.
Quick Start
from docx import Document
# Read existing document
doc = Document("document.docx")
for para in doc.paragraphs:
print(para.text)
# Create new document
doc = Document()
doc.add_heading("My Title", level=0)
doc.add_paragraph("Hello, World!")
doc.save("output.docx")
Fallback: inspect .docx without python-docx
If python-docx is unavailable but the task is read-only inspection, treat .docx as a ZIP archive and extract Word XML text directly instead of stopping:
from pathlib import Path
from zipfile import ZipFile
import re
import xml.etree.ElementTree as ET
path = Path("document.docx")
with ZipFile(path) as zf:
xml = zf.read("word/document.xml")
root = ET.fromstring(xml)
ns = {"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"}
texts = [node.text or "" for node in root.findall(".//w:t", ns)]
print(re.sub(r"\n{3,}", "\n\n", "\n".join(texts)))
Use this for content discovery and comparison only; use a real DOCX library or office converter for preserving layout, images, tables, comments, tracked changes, and styles.
When to Use
- Extracting text and tables from Word documents
- Creating professional documents programmatically
- Generating reports from templates
- Bulk document processing and modification
- Legal document redlining with tracked changes
- Converting Word documents to other formats
- Adding headers, footers, and page numbers
- Inserting images and tables into documents
Version History
- 1.1.0 (2026-01-02): Added Quick Start, When to Use, Execution Checklist, Error Handling, Metrics sections; updated frontmatter with version, category, related_skills
- 1.0.0 (2024-10-15): Initial release with python-docx, pandoc integration, redlining workflow
Sub-Skills
- Execution Checklist
- Error Handling
- Metrics
- Dependencies
Sub-Skills
- Core Capabilities
- Extract Text with Pandoc (+2)
- Basic Document Creation (+3)
- Modify Existing Document (+1)
- Step 1: Convert to Markdown (+4)
- Extract Metadata
- Working with Headers/Footers
1---2name: docx-23description: Comprehensive Word document toolkit for reading, creating, and editing .docx files. Supports text extraction, document creation with python-docx, and tracked changes via redlining workflow. Use for legal, academic, or professional document manipulation.4---56# Docx78## Overview910This skill enables comprehensive Word document operations through multiple specialized workflows for reading, creating, and editing documents.1112## Quick Start1314```python15from docx import Document1617# Read existing document18doc = Document("document.docx")19for para in doc.paragraphs:20 print(para.text)2122# Create new document23doc = Document()24doc.add_heading("My Title", level=0)25doc.add_paragraph("Hello, World!")26doc.save("output.docx")27```2829### Fallback: inspect `.docx` without `python-docx`3031If `python-docx` is unavailable but the task is read-only inspection, treat `.docx` as a ZIP archive and extract Word XML text directly instead of stopping:3233```python34from pathlib import Path35from zipfile import ZipFile36import re37import xml.etree.ElementTree as ET3839path = Path("document.docx")40with ZipFile(path) as zf:41 xml = zf.read("word/document.xml")42root = ET.fromstring(xml)43ns = {"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"}44texts = [node.text or "" for node in root.findall(".//w:t", ns)]45print(re.sub(r"\n{3,}", "\n\n", "\n".join(texts)))46```4748Use this for content discovery and comparison only; use a real DOCX library or office converter for preserving layout, images, tables, comments, tracked changes, and styles.4950## When to Use5152- Extracting text and tables from Word documents53- Creating professional documents programmatically54- Generating reports from templates55- Bulk document processing and modification56- Legal document redlining with tracked changes57- Converting Word documents to other formats58- Adding headers, footers, and page numbers59- Inserting images and tables into documents6061## Version History6263- **1.1.0** (2026-01-02): Added Quick Start, When to Use, Execution Checklist, Error Handling, Metrics sections; updated frontmatter with version, category, related_skills64- **1.0.0** (2024-10-15): Initial release with python-docx, pandoc integration, redlining workflow6566## Sub-Skills6768- [Execution Checklist](execution-checklist/SKILL.md)69- [Error Handling](error-handling/SKILL.md)70- [Metrics](metrics/SKILL.md)71- [Dependencies](dependencies/SKILL.md)7273## Sub-Skills7475- [Core Capabilities](core-capabilities/SKILL.md)76- [Extract Text with Pandoc (+2)](extract-text-with-pandoc/SKILL.md)77- [Basic Document Creation (+3)](basic-document-creation/SKILL.md)78- [Modify Existing Document (+1)](modify-existing-document/SKILL.md)79- [Step 1: Convert to Markdown (+4)](step-1-convert-to-markdown/SKILL.md)80- [Extract Metadata](extract-metadata/SKILL.md)81- [Working with Headers/Footers](working-with-headersfooters/SKILL.md)