python-docx

Create and manipulate Microsoft Word documents programmatically. Build reports, contracts, and documentation with full control over paragraphs, tables, headers, styles, and images.

5 stars

Best use case

python-docx is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Create and manipulate Microsoft Word documents programmatically. Build reports, contracts, and documentation with full control over paragraphs, tables, headers, styles, and images.

Teams using python-docx should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/python-docx/SKILL.md --create-dirs "https://raw.githubusercontent.com/vamseeachanta/workspace-hub/main/.agents/skills/data/office/python-docx/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/python-docx/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How python-docx Compares

Feature / Agentpython-docxStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Create and manipulate Microsoft Word documents programmatically. Build reports, contracts, and documentation with full control over paragraphs, tables, headers, styles, and images.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Python Docx

## Overview

Python-docx is a Python library for creating and manipulating Microsoft Word (.docx) documents. This skill covers comprehensive patterns for document automation including:

- **Document creation** from scratch or templates
- **Paragraph formatting** with styles, fonts, and alignment
- **Table generation** with merged cells, styles, and formatting
- **Headers and footers** with page numbers and dynamic content
- **Image insertion** with sizing and positioning
- **Style management** for consistent document appearance
- **Template manipulation** for document workflows
- **Mail merge patterns** for bulk document generation

## When to Use This Skill

### USE when:

- Creating Word documents programmatically from data
- Generating reports with consistent formatting
- Building contracts, invoices, or legal documents
- Automating template-based document creation
- Modifying existing Word documents
- Creating documents with complex table structures
- Generating technical documentation with code blocks
- Building multi-section documents with headers/footers
- Creating documents with embedded images and charts
- Batch processing document generation
### DON'T USE when:

- Simple template filling (use docx-templates instead)
- PDF generation is the final output (use pypdf or reportlab)
- Need real-time collaborative editing
- Document requires complex macros or VBA
- Need to preserve complex Word features (use COM automation on Windows)
- Only need to extract text from documents (use python-docx2txt)

## Prerequisites

### Installation

```bash
# Using pip
pip install python-docx

# Using uv (recommended)
uv pip install python-docx

# With image support
pip install python-docx Pillow

# Full installation with all optional dependencies
pip install python-docx Pillow lxml
```
### Verify Installation

```python
from docx import Document
from docx.shared import Inches, Pt, Cm
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.enum.table import WD_TABLE_ALIGNMENT

print("python-docx installed successfully!")
```

## Version History

### 1.0.0 (2026-01-17)

- Initial skill creation
- Core capabilities documentation
- 6 complete code examples
- Integration patterns
- Best practices guide
- Troubleshooting section

## Resources

- **Official Documentation**: https://python-docx.readthedocs.io/
- **GitHub Repository**: https://github.com/python-openxml/python-docx
- **PyPI Package**: https://pypi.org/project/python-docx/
- **Open XML SDK Reference**: https://docs.microsoft.com/en-us/office/open-xml/

## Related Skills

- **docx-templates** - Jinja2-style template rendering for Word documents
- **pypdf** - PDF manipulation and generation
- **openpyxl** - Excel file automation
- **python-pptx** - PowerPoint presentation generation

---

*This skill provides comprehensive patterns for Word document automation refined from production document generation systems.*

## Sub-Skills

- [1. Basic Document Creation](1-basic-document-creation/SKILL.md)
- [2. Advanced Paragraph Formatting](2-advanced-paragraph-formatting/SKILL.md)
- [3. Table Creation and Formatting](3-table-creation-and-formatting/SKILL.md)
- [4. Headers, Footers, and Page Setup](4-headers-footers-and-page-setup/SKILL.md)
- [5. Image Insertion and Positioning](5-image-insertion-and-positioning/SKILL.md)
- [6. Style Management and Custom Styles](6-style-management-and-custom-styles/SKILL.md)
- [Report Generation from Database (+1)](report-generation-from-database/SKILL.md)
- [Batch Document Generation](batch-document-generation/SKILL.md)
- [1. Document Structure (+3)](1-document-structure/SKILL.md)
- [Common Issues](common-issues/SKILL.md)

Related Skills

python-pptx

5
from vamseeachanta/workspace-hub

Create and manipulate PowerPoint presentations programmatically. Build slide decks with layouts, shapes, charts, tables, and images. Generate data-driven presentations from templates.

pypdf

5
from vamseeachanta/workspace-hub

Manipulate PDF documents programmatically. Merge, split, rotate, and watermark PDFs. Extract text and metadata. Handle form filling and encryption/decryption.

openpyxl

5
from vamseeachanta/workspace-hub

Create and manipulate Microsoft Excel workbooks programmatically. Build spreadsheets with formulas, charts, conditional formatting, and pivot tables. Handle large datasets efficiently with streaming mode.

python-import-path-mismatch-debugging

5
from vamseeachanta/workspace-hub

Diagnose and fix ModuleNotFoundError when a package is installed but imports still fail due to environment/path mismatches

python-import-path-debugging

5
from vamseeachanta/workspace-hub

Diagnose ModuleNotFoundError when a package is installed but still fails to import

python-debugpy

5
from vamseeachanta/workspace-hub

Debug Python: pdb REPL + debugpy remote (DAP).

python-gis-ecosystem

5
from vamseeachanta/workspace-hub

Python GIS Ecosystem Skill — GDAL/OGR, Fiona, Shapely, Rasterio, GeoPandas, pyproj, Folium, xarray/rioxarray, Cartopy — foundational GIS libraries

python-project-template

5
from vamseeachanta/workspace-hub

Generate standardized Python project structure with pyproject.toml, UV environment, pytest configuration, and workspace-hub compliance. Creates production-ready project scaffolding.

python-scientific-computing

5
from vamseeachanta/workspace-hub

Python for engineering analysis, numerical computing, and scientific workflows using NumPy, SciPy, SymPy

xlsx-to-python

5
from vamseeachanta/workspace-hub

Convert Excel calculation spreadsheets to Python code — extract formulas, build dependency graphs, generate pytest tests using cell values as assertions, and produce dark-intelligence archive YAMLs.

docx-templates

5
from vamseeachanta/workspace-hub

Template-based Word document generation using Jinja2 syntax. Create reports, contracts, and documents with loops, conditionals, tables, and mail merge capabilities.

excel-workbook-to-python-v2

5
from vamseeachanta/workspace-hub

Convert engineering Excel workbooks to Python code using Codex Desktop cowork on Windows. Proven superior quality vs Linux openpyxl extraction (24 vs 7 functions, 81 vs 53 tests). Validated on Ballymore jumper installation analysis.