Skip to content
Back to skills

Docx Authoring

ASecurity

Write and edit Word documents with python-docx. Use when producing or editing a .docx.

  • 2 stars
  • 0 votes
  • 0 copies
  • 12 views
  • Added October 12, 2026
devopspython

Security analysis

A100/100

Scanned October 12, 2026

npx -y skills add RorroRojas3/enterprise-gpt --skill docx-authoring --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Docx Authoring?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Docx Authoring
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/rorrorojas3-docx-authoring/badge)](https://www.skillsdirectory.com/skills/rorrorojas3-docx-authoring)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: docx-authoring
description: Write and edit Word documents with python-docx. Use when producing or editing a .docx.
---

# Authoring .docx

`python-docx` 1.2.0 is installed. `docx2pdf`, `mammoth` and `pandoc` are not, and nothing can be installed.

## Create

```python
from docx import Document
from docx.shared import Inches

doc = Document()
doc.add_heading("Quarterly Review", level=0)
doc.add_paragraph("Prepared for the leadership team.")

doc.add_heading("Highlights", level=1)
for line in ("Revenue up 12%", "Two new markets", "Churn flat"):
    doc.add_paragraph(line, style="List Bullet")

table = doc.add_table(rows=1, cols=2)
table.style = "Light Grid Accent 1"
header = table.rows[0].cells
header[0].text, header[1].text = "Metric", "Value"
for metric, value in (("Revenue", "$4.1M"), ("Churn", "2.1%")):
    row = table.add_row().cells
    row[0].text, row[1].text = metric, value

doc.save("/mnt/data/quarterly-review.docx")
```

## Edit an existing document

Open it, change it, save under a **new** name. Never overwrite the source.

```python
doc = Document("/mnt/data/<input>.docx")
for paragraph in doc.paragraphs:
    if "TBD" in paragraph.text:
        for run in paragraph.runs:
            run.text = run.text.replace("TBD", "2026-Q1")
doc.save("/mnt/data/quarterly-review-updated.docx")
```

Editing a run rather than the paragraph is what preserves the paragraph's formatting; assigning to `paragraph.text` throws it away.

## Notes

- `add_heading(level=0)` is the title style; levels 1-9 are headings.
- A style name that is not in the default template raises `KeyError`. Stick to the built-in names above.
- Images: `doc.add_picture(path, width=Inches(6))`, and only from a file already in `/mnt/data`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in devops →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.