doc-office — Word, Excel, PowerPoint
The deliverable is a .docx, .xlsx, or .pptx. Reach for the right library; **prefer templating over
hand-building** a document element by element.
Word
- Templated (same shape each time — a letter, a report) → docxtpl: Jinja2 inside a real .docx
template the user designed in Word. Styling stays in the template, data in code.
- From scratch → python-docx: headings, tables, images. Keep to named styles, don't hand-format
every run.
Excel
- openpyxl — read+write: formulas, styles, conditional formatting, charts, named ranges.
- XlsxWriter — write-only, but richer formatting/charts and faster on big sheets (
constant_memorymode). - pandas
to_excelfor a quick data dump; drop to openpyxl/XlsxWriter for formatting and formulas. - Keep numbers as real formulas (
=SUM(...)), not pre-computed strings — the user expects a live model.
Set column widths, freeze the header row, format currency/dates, add a total row.
PowerPoint
- python-pptx — slides from data: pick a layout, fill placeholders, add tables/charts/images. Reuse a
branded template (Presentation("template.pptx")) instead of the default theme.
Quality gate
- Open the file in the real app (or LibreOffice headless) — valid-looking OOXML a viewer rejects is not "done".
- Named styles + a template beat inline formatting for anything the user will maintain.
Pitfalls
- python-docx can't "update" a table of contents — Word rebuilds it on open (tell the user to press F9).
- openpyxl silently drops charts/macros it doesn't understand on round-trip — don't blindly read+write a
macro workbook (.xlsm); use the right tool or keep a copy.
- Merged cells + formulas fight — set the value on the top-left cell only.
*Learned from the community's document skills (incl. Anthropic's official DOCX/XLSX/PPTX skills) —
re-implemented as guidance over open libraries, not vendored. See docs/ECOSYSTEM.md. Pairs with doc-pdf.*