Generating Word Docs

Creates Word documents (.docx) for reports, briefs, letters, and other documents meant to be read rather than edited as code. Use whenever the deliverable is a written document and a polished, human-readable format is expected instead of markdown.

aaravriyer193 Updated

File contents

Generating Word documents

Never hand-write .docx with write_file — it's a zipped XML format and will corrupt. Build it with python-docx instead.

pip install python-docx
from docx import Document

doc = Document()
doc.add_heading("Title", level=1)
doc.add_paragraph("Body text.")
doc.add_heading("Section", level=2)
doc.add_paragraph("More text.", style="List Bullet")
doc.save("/home/user/report.docx")

Write this as a script with write_file, run it with shell, then present_file the .docx — never the script.

For tables:

table = doc.add_table(rows=1, cols=3)
table.style = "Light Grid Accent 1"
hdr = table.rows[0].cells
hdr[0].text, hdr[1].text, hdr[2].text = "Name", "Value", "Notes"

For a cover page or letterhead, add a page break with doc.add_page_break() and keep the first page minimal.

aaravriyer193/skills/tree/main/generating-word-docs commit 9ae6be66bf

Frequently asked questions

npx skillmds@latest add aaravriyer193/generating-word-docs