build-office-docs
Skill9 starsChanged 5 months agoApache-2.0View on GitHub
Generates and edits Office documents (DOCX/PPTX) programmatically from data or templates, including styled reports, tables, headers/footers, tracked changes, and slide decks.
In this repository147 other files it gives its agents.
- second-brain/AGENTS.mdAGENTS.md
- second-brain/CLAUDE.mdCLAUDE.md
- agent-tool-mcp-builderSkill
- api-design-reviewSkill
- async-concurrency-correctnessSkill
- audit-accessibility-wcagSkill
- audit-license-complianceSkill
- audit-technical-seoSkill
- auth-jwt-sessionSkill
- author-codemodSkill
- brainstorm-designSkill
- build-audit-loggingSkill
- build-cdc-streaming-pipelineSkill
- build-cli-toolSkill
- build-data-tableSkill
- build-etl-pipelineSkill
- build-form-validationSkill
- build-native-mobile-uiSkill
- build-offline-first-syncSkill
- build-react-componentSkill
- build-realtime-channelSkill
- build-spreadsheetSkill
- build-vector-searchSkill
- caching-strategySkill
- cicd-pipeline-authorSkill
- cloud-cost-optimizeSkill
- code-commentsSkill
- code-reviewSkill
- compose-local-dev-stackSkill
- configure-bundler-buildSkill
- configure-dns-tlsSkill
- configure-reverse-proxy-lbSkill
- configure-security-headers-cspSkill
- contract-testingSkill
- datetime-timezone-correctnessSkill
- db-migration-safetySkill
- debug-ci-pipeline-failureSkill
- debug-flaky-testsSkill
- debug-frontend-browserSkill
- debug-root-causeSkill
- defend-llm-prompt-injectionSkill
- deliver-webhooksSkill
- dependency-upgradeSkill
- deploy-releaseSkill
- design-api-paginationSkill
- design-authorization-modelSkill
- design-backup-dr-recoverySkill
- design-event-sourcing-cqrsSkill
- design-multi-tenancySkill
- design-protobuf-grpc-serviceSkill
- design-relational-schemaSkill
- design-search-index-infraSkill
- design-state-machineSkill
- design-token-systemSkill
- diff-table-paritySkill
- distributed-locks-leasesSkill
- dockerfile-optimizeSkill
- encrypt-sensitive-dataSkill
- error-messageSkill
- estimate-workSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
Do NOT use this for: plain .txt/.md/.csv output, PDFs (use a PDF/HTML-to-PDF path), or .doc/.ppt legacy binary formats (convert to OOXML …
- Very specific: line 46
Start from Presentation('template.pptx') to inherit master/layouts.
- Distinctive: line 80
If validation cannot run (no Word/LibreOffice available and the library re-open is the only check), state that the file passed …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When to Use
Trigger this skill when the task produces or modifies a .docx or .pptx file:
- Generate a Word report/letter/memo from data or a written outline.
- Fill a DOCX/PPTX template that has
{{placeholder}}fields or named shapes. - Mail-merge one template over a row set (one output file per row, or one file with repeated sections).
- Build a slide deck from a structured outline (title + bullets + notes per slide).
- Edit an existing
.docx: find-replace, insert/restyle tables, add headers/footers/page numbers, or apply tracked changes.
Do NOT use this for: plain .txt/.md/.csv output, PDFs (use a PDF/HTML-to-PDF path), or .doc/.ppt legacy binary formats (convert to OOXML first via LibreOffice soffice --headless --convert-to docx).
Steps
- Classify the job along two axes before writing code:
- Format:
docx(Word) vspptx(PowerPoint). Decide from the request, not the extension alone. - Mode:
from-scratch(build a new file) ·template(fill placeholders in an existing file) ·edit-existing(mutate a real document, preserving its styles). Print the chosen{format, mode}before proceeding — the library and approach differ per cell.
- Format:
- Pick the library by {format, mode}. Do not invent a new dependency if one is already in the repo:
- docx, from-scratch / edit-existing →
python-docx. - docx, template with
{{fields}}/Jinja loops →docxtpl(renders Jinja2 inside a real .docx, keeps styles). - pptx, any mode →
python-pptx. - Low-level changes these libraries can't express (tracked changes
w:ins/w:del, custom XML, content controls, theme colors) → edit the OOXML directly: a.docx/.pptxis a zip of XML parts (word/document.xml,ppt/slides/slideN.xml). Unzip, edit XML vialxml, re-zip. Confirm the package is installed (pip show python-docx docxtpl python-pptx); install into the project env, not globally, if missing.
- docx, from-scratch / edit-existing →
- DOCX — from scratch (
python-docx):- Structure with real styles, not manual formatting:
doc.add_heading(text, level=N),doc.add_paragraph(text, style='List Bullet'|'List Number'). Reusedoc.styles/ a base template (Document('template.docx')) so output inherits the org's fonts and theme. - Tables:
t = doc.add_table(rows, cols), sett.style = 'Light Grid Accent 1'(must be a style that exists in the doc, else it errors). Cell styling lives on the run inside the cell paragraph:cell.paragraphs[0].add_run(text).bold = True; widths needtblLayoutfixed (t.autofit = False+ set eachcell.width). - Headers/footers/page numbers:
section.header/section.footer; a page-number field requires afldSimple/w:instrText PAGEXML run (python-docxhas no helper — inject the XML viarun._r.append(...)). - Images:
doc.add_picture(path, width=Inches(...)); missing files raise, so check the path first.
- Structure with real styles, not manual formatting:
- DOCX — template fill & mail-merge (
docxtpl):- Author the template with Jinja in real Word text:
{{ customer_name }},{% for row in items %}...{% endfor %}(use{%tr ... %}to repeat table rows,{%p ... %}to repeat paragraphs). Tag names must match the context dict keys exactly. - Render:
tpl = DocxTemplate('tpl.docx'); tpl.render(context); tpl.save(out). - Mail-merge = loop the data rows: render one output per row →
out_{i}.docx(or_{key}.docx), OR pass a list into one template and use a{%tr%}/{%p%}loop for a single combined file. Decide which the user wants up front. - Insert images/rich runs via
tpl.new_subdoc()/InlineImage, not raw strings, so styling survives.
- Author the template with Jinja in real Word text:
- PPTX (
python-pptx):- Start from
Presentation('template.pptx')to inherit master/layouts;Presentation()alone gives the default theme only. - Per slide: pick a layout (
prs.slide_layouts[idx]),slide = prs.slides.add_slide(layout), then fill named placeholders by index/type (slide.placeholders[0].text = title) — do not assume placeholder 1 is always the body; inspect[ph.placeholder_format.idx for ph in slide.placeholders]. - Bullets: write into the body placeholder's
text_frame, oneparagraphper bullet, setparagraph.levelfor indent. - Speaker notes:
slide.notes_slide.notes_text_frame.text = notes. - Charts/tables:
slide.shapes.add_chart(...)with aCategoryChartData, oradd_table(rows, cols, x, y, w, h).
- Start from
- Edit-existing without nuking styles: open the real file, mutate only target nodes. For find-replace in
python-docx, replace at the run level (text can be split across runs — naiveparagraph.text = ...drops formatting); join/split runs carefully or use a known replace helper. - Tracked changes are not in
python-docx's API — do it at the XML layer: an insertion is a<w:ins w:author w:date>wrapping the new run; a deletion wraps the old run in<w:del>with the text in<w:delText>. Set author/date attributes. Verify Word shows them under Review → Track Changes after opening. - Render to the requested path, then validate (step into ## Verify) before declaring done. Report the absolute output path and confirm the file opens.
Common Errors
- Corrupt file after manual XML edits — re-zipping with wrong compression/structure, missing
[Content_Types].xml, or a stray byte breaks the package and Word says "needs repair". Always round-trip throughzipfile(preserve all parts), and re-open with the library after writing to catch corruption early. - Style does not exist → exception or silent no-op.
t.style = 'Some Style'/add_paragraph(style=...)only works if that style is defined in the document. Build from a template that contains the style, or add the style definition first. Style names are case- and space-sensitive. - Fonts/styles "not embedded" → output looks wrong on another machine. OOXML references fonts by name; it does not embed them. If a specific font is required, embed it (
<w:embedRegular>font part) or restrict to fonts the consumer has. Theme colors only resolve if the theme part is present (another reason to start from a real template). - Merge-field / placeholder mismatch. A
{{tag}}with no matching context key renders empty or raises (jinja2.UndefinedError); a key with no tag is silently ignored. Diff the template's tag set against the context dict keys before rendering. Word sometimes splits{{ tag }}across runs sodocxtplcan't see it — keep each tag typed in one run (retype it cleanly in Word). - find-replace drops formatting because Word stores one logical word across multiple
<w:r>runs. Replacingparagraph.textcollapses runs and loses bold/italic/links. Operate run-by-run or use a run-aware replacer. - PPTX placeholder index assumption — layouts differ; index 1 is not always the content body. Always enumerate
slide.placeholdersand match byplaceholder_format.type/idx. add_picture/template path is relative and the working dir differs at run time →FileNotFoundError. Use absolute paths.- Tracked changes invisible because
w:author/w:dateare missing or the run wasn't wrapped inw:ins/w:del— Word then shows the edit as a normal change. Confirm the wrapping nodes and attributes exist.
Verify
A generated/edited Office file is done only when ALL hold:
- The file exists at the reported absolute path and has non-trivial size (> a few KB; a 0-byte or tiny file means the write failed).
- It is a valid OOXML package:
unzip -l <file>lists parts including[Content_Types].xmlandword/document.xml(docx) orppt/presentation.xml(pptx) — no zip error. - It re-opens with the library without exception:
Document(out)(docx) orPresentation(out)(pptx) loads, and a spot-check reads back expected content (a heading's text, a known cell value, slide count == expected). - For templates/mail-merge: no
{{/}}/{%literals remain in the output (unzip -p <file> word/document.xml | grep -c '{{'returns 0), and one output file exists per data row when per-row mode was chosen. - For tracked changes:
word/document.xmlcontains the expected<w:ins>/<w:del>nodes with author+date; opening in Word shows them under Review. - If a specific font/style/theme was requested, it is present (style name resolves; theme/font part exists in the zip).
If validation cannot run (no Word/LibreOffice available and the library re-open is the only check), state that the file passed structural+library validation but was not opened in a real Office client.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

