docx
What it does
This skill lets an AI agent work with Microsoft Word documents. It is for people who need reports, letters, or memos written as Word files, or existing Word files read and edited.
When to use it
- βWhen you need a Word report, letter, or memo made as a .docx file.
- βWhen you want the text or tables pulled out of an existing Word file.
- βWhen you need tracked changes or comments added to a Word document.
Skill link
https://github.com/HKUDS/DeepTutor/blob/main/deeptutor/skills/builtin/docx/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βTurn these notes into a Word report with headings, a table, and page numbers.β
5 new skills a week. 1 minute to read.
How it works
The agent uses the python-docx library for most tasks, and writes raw Word XML for advanced cases such as tracked changes and comments. It saves a new output file rather than overwriting the original.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
DOCX (Microsoft Word)
A .docx is a ZIP of XML parts. Body text lives in word/document.xml. Two tiers:
- Default β
python-docx(preinstalled): create, read, and simple edits. Use for almost everything. - Advanced β raw OOXML via
zipfile: only for what python-docx cannot express β tracked changes (redlines), comments, and exact-fidelity edits that must preserve every untouched byte. See Raw OOXML.
Runtime
Use exec with complete Python source (language: python). python-docx is
preinstalled. Prefer creating, saving, reopening, and validating the deliverable
in one call; later calls can revise the same relative filename. Follow the
turn's User workspace instructions for locating inputs, output boundaries,
and presenting the finished file. When editing, write a new output unless the
user explicitly requested an authorized replacement.
Read / extract
from docx import Document
doc = Document("in.docx")
text = "\n".join(p.text for p in doc.paragraphs) # body paragraphs
for tbl in doc.tables: # tables
for row in tbl.rows:
print([c.text for c in row.cells])
doc.paragraphs skips text inside tables, headers/footers, and text boxes β iterate doc.tables and doc.sections[i].header/.footer for those. Each paragraph's style: p.style.name (e.g. "Heading 1").
To read tracked changes, parse the XML directly β python-docx ignores <w:ins>/<w:del>:
import zipfile, re
xml = zipfile.ZipFile("in.docx").read("word/document.xml").decode("utf-8")
# inserted text = <w:ins>β¦<w:t>β¦ deleted = <w:del>β¦<w:delText>β¦
print(re.findall(r"<w:t[^>]*>(.*?)</w:t>", xml))
Create
from docx import Document
from docx.shared import Pt, Inches, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
doc = Document() # default template page size
doc.add_heading("Quarterly Report", level=0) # 0 = title; 1..9 = H1..H9
p = doc.add_paragraph("Intro paragraph. ")
run = p.add_run("Bold tail.")
run.bold = True
doc.add_paragraph("First item", style="List Bullet") # real list style, never a "β’ " literal
doc.add_paragraph("Step one", style="List Number")
# Table β header row + data
tbl = doc.add_table(rows=1, cols=2)
tbl.style = "Light Grid Accent 1"
tbl.rows[0].cells[0].text, tbl.rows[0].cells[1].text = "Metric", "Value"
for k, v in [("Revenue", "1.2M"), ("Growth", "15%")]:
c = tbl.add_row().cells
c[0].text, c[1].text = k, v
doc.add_picture("chart.png", width=Inches(5)) # image, scaled to width
doc.add_page_break()
doc.save("out.docx")
# Validate immediately; later exec calls can also reopen this relative path.
check = Document("out.docx")
assert check.paragraphs, "generated DOCX has no paragraphs"
import zipfile
with zipfile.ZipFile("out.docx") as package:
assert package.testzip() is None, "generated DOCX has a corrupt ZIP member"
Rules:
- Never type bullet/number characters (
β’,1.) into text β usestyle="List Bullet"/"List Number". Only list styles defined in the doc's template are available. - No
\ninside a run β each visual line is its ownadd_paragraph. - Built-in style names must match the template (e.g.
"Heading 1","List Bullet"); a wrong name raisesKeyError. - Units:
Pt,Inches,Cmfromdocx.shared. Colors:RGBColor(0x1F,0x4E,0x79).
Page setup, headers/footers, page numbers
from docx.shared import Inches
sec = doc.sections[0]
sec.page_width, sec.page_height = Inches(8.5), Inches(11) # Letter
sec.top_margin = sec.bottom_margin = Inches(1)
sec.header.paragraphs[0].text = "Confidential"
Page-number fields aren't in the python-docx API; inject the field XML into a footer run:
from docx.oxml.ns import qn
from docx.oxml import OxmlElement
def add_page_number(paragraph):
for t in ("begin", "instr", "end"):
r = OxmlElement("w:r")
if t == "instr":
fld = OxmlElement("w:instrText")
fld.set(qn("xml:space"), "preserve")
fld.text = "PAGE"
else:
fld = OxmlElement("w:fldChar")
fld.set(qn("w:fldCharType"), t)
r.append(fld)
paragraph._p.append(r)
add_page_number(doc.sections[0].footer.paragraphs[0])
A clickable Table of Contents is also a field; Word shows "right-click β Update Field" until refreshed. Same pattern with instrText = TOC \o "1-3" \h \z \u.
Edit existing (simple)
python-docx preserves the rest of the doc
FAQ
Does it work with PDF or Excel files?
No. The skill is for Word files, and it says PDF, Excel, PowerPoint, and Google Docs are outside its scope.
Can it add a table of contents?
Yes. The skill covers tables of contents and page numbers.
Can it make tracked changes?
Yes. It can apply tracked changes and comments through its advanced method.
Details
Original description by the author
Read, create, or edit Microsoft Word .docx files β extract/summarize text and tables, generate reports/letters/memos with headings, tables, images, TOC and page numbers, do find-and-replace, or apply tracked changes (redlines) and comments. Use whenever the user has a .docx or wants a Word deliverable. Not for PDF, .xlsx, .pptx, or Google Docs.
repo: HKUDS/DeepTutor
Popularity
- GitHub stars
- 54k
- Ranking position
- #3368
- License
- Apache-2.0
- Updated
- 10/31/2026
Comments
- β¦
More skills from this repository
deeptutor-cli
54kHelps your agent set up and run DeepTutor, a learning platform, through its command line, including knowledge bases, notebooks, and the web app.
Helps your agent read, merge, split, fill, and create PDF files, including pulling text and tables out of them.
pptx
54kLets your agent create, read, and edit PowerPoint decks, including slide text, speaker notes, charts, and images.
skill-creator
54kTeaches your agent to write or improve DeepTutor skills, the short instruction packages that teach an AI a specific task.
Similar skills
feishu-doc
394kHelps your agent read, create, and edit Feishu cloud documents, including text, images, and tables, using the document tool.
feishu-drive
394kLets your agent browse, organize, and comment on files in a Feishu cloud folder that has been shared with the bot.
feishu-perm
394kHelps your agent check and change who can access a Feishu file, choosing the smallest permission that meets your request.