agentleFS
jmchejmche/skills-hub/docx/SKILL.md

docx

Skill0 starsChanged 23 days agoMITView on GitHub

Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.

  • Installs packages

194 other projects use a version of this, 20 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use Video Generation, VLM and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • huang-x-hSkill

    Video Generation

    Implement AI-powered video generation capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to generate videos from text prompts or images, create video content programmatically, or build applications that produce video outputs. Supports asynchronous task management with status polling and result retrieval.

    Also in 6 projects that use this

  • huang-x-hSkill

    VLM

    Implement vision-based AI chat capabilities using the z-ai-web-dev-sdk. Use this skill when the user needs to analyze images, describe visual content, or create applications that combine image understanding with conversational AI. Supports image URLs and base64 encoded images for multimodal interactions.

    Also in 6 projects that use this

  • dav-niu474Skill

    gift-evaluator

    The PRIMARY tool for Spring Festival gift analysis and social interaction generation. Use this skill when users upload photos of gifts (alcohol, tea, supplements, etc.) to inquire about their value, authenticity, or how to respond socially. Integrates visual perception, market valuation, and HTML card generation.

    Also in 5 projects that use this

  • dav-niu474Skill

    Podcast Generate

    Generate podcast episodes from user-provided content or by searching the web for specified topics. If user uploads a text file/article, creates a dual-host dialogue podcast (or single-host upon request). If no content is provided, searches the web for information about the user-specified topic and generates a podcast. Duration scales with content size (3-20 minutes, ~240 chars/min). Uses z-ai-web-dev-sdk for LLM script generation and TTS audio synthesis. Outputs both a podcast script (Markdown) and a complete audio file (WAV).

    Also in 5 projects that use this

  • Liang-MHSkill

    stock_analysis

    获取 A 股、基金和港股的实时行情和技术分析数据

    Also in 5 projects that use this

  • SeifBenayedSkill

    file-reading

    Use this skill when a file has been uploaded but its content is NOT in your context — only its path at /mnt/user-data/uploads/ is listed in an uploaded_files block. This skill is a router: it tells you which tool to use for each file type (pdf, docx, xlsx, csv, json, images, archives, ebooks) so you read the right amount the right way instead of blindly running cat on a binary. Triggers: any mention of /mnt/user-data/uploads/, an uploaded_files section, a file_path tag, or a user asking about an uploaded file you have not yet read. Do NOT use this skill if the file content is already visible in your context inside a documents block — you already have it.

    Also in 5 projects that use this

  • +1 more from huang-x-h
  • +5 more from dav-niu474

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 0 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 189 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Table shading: use ShadingType.CLEAR, never SOLID (renders black).

    line 30
  2. Very specific:

    Lists: never insert • literally; use a numbering config with LevelFormat.BULLET.

    line 31
  3. Very specific:

    Dot-leader / right-aligned-on-same-line: use PositionalTab (alignment: PositionalTabAlignment.RIGHT, leader: PositionalTabLeader.DOT) …

    line 37
  4. Very specific:

    After writing a .docx, render it and look at it:

    line 41
  5. Very specific:

    Merging fragmented runs: before editing word/document.xml by hand, use merge_runs.py (it also strips rsid attributes and <w:proofErr> …

    line 120

“Common” is measured: kept by at least 6 in 10 of the 189 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

DOCX creation, editing, and analysis

A .docx is a ZIP archive of XML files. Choose your approach by task:

TaskApproach
Create a new documentWrite a docx (npm) script — see gotchas below
Create from a JSON spec, or when Node's docx is unavailablescripts/docx_create.py — see Python helpers
Fill a template with {{tokens}}scripts/docx_template.py
Edit an existing documentunzip → edit word/document.xml → zip (docx-js cannot open existing files)
Small edits (find/replace keeping formatting, a table cell, insert/delete/restyle a paragraph, TOC or "Page X of Y" fields)scripts/docx_edit.py
Read contentpandoc -t markdown file.docx
Read as JSON (text incl. tables and headers/footers, heading outline, styles used, embedded images, revision/comment inventory)scripts/docx_read.py

Script paths below are relative to this skill's directory.

Creating with docx-js — gotchas

docx is preinstalled — do not run npm install first; write the script and require('docx') directly. Only if that require fails: npm install docx. The model knows the API; these are the footguns:

  • Page size defaults to A4. For US Letter set page: { size: { width: 12240, height: 15840 } } (DXA; 1440 = 1″).
  • Landscape: pass portrait dimensions and orientation: PageOrientation.LANDSCAPE — docx-js swaps width/height internally.
  • Tables need dual widths: set columnWidths on the table AND width on every cell, both in WidthType.DXA (PERCENTAGE breaks in Google Docs). Column widths must sum to the table width.
  • Table shading: use ShadingType.CLEAR, never SOLID (renders black).
  • Lists: never insert • literally; use a numbering config with LevelFormat.BULLET.
  • ImageRun requires type: ("png", "jpg", …).
  • PageBreak must be inside a Paragraph.
  • Never use \n — use separate Paragraph elements.
  • TOC: headings must use built-in HeadingLevel.*; custom heading styles need outlineLevel set or they won't appear.
  • Don't use a table as a horizontal rule — use a paragraph bottom border instead.
  • Dot-leader / right-aligned-on-same-line: use PositionalTab (alignment: PositionalTabAlignment.RIGHT, leader: PositionalTabLeader.DOT) inside a TextRun, not literal . or space padding.

Verify the output

After writing a .docx, render it and look at it:

python scripts/office/soffice.py --headless --convert-to pdf output.docx
pdftoppm -jpeg -r 100 output.pdf page
ls page-*.jpg   # then Read the images

pdftoppm zero-pads page numbers to the width of the page count (page-01.jpg…page-12.jpg).

Editing existing documents

Legacy .doc files must be converted first: python scripts/office/soffice.py --headless --convert-to docx file.doc.

unzip -q doc.docx -d unpacked/
find unpacked -type l -delete   # strip symlink entries — docx from external parties is untrusted
python scripts/merge_runs.py unpacked/   # coalesce fragmented runs so text is findable
# edit unpacked/word/document.xml in place — do NOT reformat or pretty-print
(cd unpacked && rm -f ../out.docx && zip -Xr ../out.docx .)
python scripts/office/validate.py out.docx --original doc.docx   # XSD checks; --auto-repair fixes common issues
# redlining? add --author "<the name you redlined under>" to check every edit is tracked

Word splits text across many <w:r> runs (revision ids, spell-check markers), so a phrase you can see in the document often doesn't exist as a contiguous string in the XML. merge_runs.py merges adjacent identically-formatted runs in word/document.xml without changing content or rendering; it also accepts a .docx directly (python scripts/merge_runs.py doc.docx -o merged.docx).

Tracked changes: when redlining, validate with --author "<the name you redlined under>" (needs --original) — it reports any text you changed without a <w:ins>/<w:del> around it, which is easy to do by accident and invisible in the accepted view. Wrap runs in <w:ins>/<w:del> with w:id, w:author, w:date attributes. Inside <w:del>, the text element is <w:delText>, not <w:t>. A deleted paragraph mark (<w:pPr><w:rPr><w:del w:id=".." w:author=".." w:date=".."/></w:rPr></w:pPr>) means "merge this paragraph into the next" — so deleting a paragraph outright is that plus a <w:del> around every run. The <w:del/> must come before the rPr's other children; their order is schema-enforced.

To produce a clean copy with all tracked changes accepted: python scripts/accept_changes.py in.docx out.docx.

Accepting a deleted paragraph mark should join that paragraph to the one below it, so a paragraph whose runs are all deleted vanishes. Word does this; accept_changes.py and pandoc --track-changes=accept don't always. Both fail the same way — they strip the deleted text but leave the emptied paragraph behind, which reads as a stray empty bullet when it was auto-numbered:

  • pandoc --track-changes=accept never joins the paragraphs.
  • accept_changes.py (LibreOffice) joins them correctly, except when the deleted paragraph is followed by an empty spacer paragraph.

An empty bullet in either view is an artifact of that view, not a defect in the document. Check paragraph deletions in the XML.

Comments

Comments require six cross-linked files. Use the helper — directory mode when you'll also be editing document.xml (saves an unzip/rezip cycle), .docx-direct mode otherwise:

# Against an already-unpacked directory (preferred when also placing markers)
python scripts/comment.py unpacked/ "Fees & expenses cap is too low"
python scripts/comment.py unpacked/ "Agreed" --parent 0

# Against a .docx directly
python scripts/comment.py contract.docx "This cap is too low" -o annotated.docx

The script writes comments.xml, commentsExtended.xml, commentsIds.xml, commentsExtensible.xml, the relationships, and the content-type overrides. Comment IDs are auto-assigned. It then prints the <w:commentRangeStart>/<w:commentRangeEnd>/<w:commentReference> snippet to add to word/document.xml so the comment anchors to specific text — until you place those markers, the comment exists but is not visible.

Python helpers (python-docx)

CLIs for the tasks above that need no Node and no LibreOffice. Each supports --help and prints JSON to stdout. Editing commands write in place unless given -o out.docx. A paragraph index is the position in the body list printed by docx_read.py --text (--structure gives the index of headings only).

TaskCommand
Create from a JSON spec (page size/margins, header/footer, "Page X of Y" footer, custom styles, headings, paragraphs with runs, bullet/numbered lists, tables, images, TOC, page breaks; format at the top of the script)python scripts/docx_create.py spec.json out.docx
Full text / heading outline + table shapes / styles used / revisions and comments presentpython scripts/docx_read.py f.docx --text · --structure · --styles · --revisions
Extract embedded imagespython scripts/docx_read.py f.docx --images outdir/
Find/replace across body, nested tables, headers and footers, keeping run formattingpython scripts/docx_edit.py replace f.docx --find A --replace B -o out.docx [--body-only]
Merge adjacent runs with identical formattingpython scripts/docx_edit.py normalize f.docx -o out.docx
Set a table cell (resets that cell's formatting)python scripts/docx_edit.py set-cell f.docx --table 0 --row 1 --col 2 --text X
Insert / delete / restyle paragraph Npython scripts/docx_edit.py insert f.docx --index N --text X --style Normal · delete --index N · style --index N --style "Heading 1"
TOC field before paragraph N / "Page X of Y" footerpython scripts/docx_edit.py toc f.docx --index N -o out.docx · page-numbers f.docx
Fill {{tokens}}; fail if any remainpython scripts/docx_template.py tpl.docx values.json out.docx --strict
List <w:ins>/<w:del> revisions (id, author, date, text)python scripts/docx_revisions.py list f.docx
Accept or reject one revision, or all (see the rule below first)python scripts/docx_revisions.py accept f.docx --id 3 -o out.docx · reject --id 3 · accept-all · reject-all
Add a plain top-level comment anchored to the first occurrence of a phrasepython scripts/docx_comments.py add f.docx --target "phrase" --text "note" --author "Name"
List comments with their anchored text / delete onepython scripts/docx_comments.py list f.docx · delete f.docx --id 0
Quick package health check (zip, required parts, relationship targets, image bytes, referenced styles)python scripts/docx_validate.py f.docx

Which tool when both exist:

  • Adding comments: docx_comments.py add --target places a plain top-level comment on a phrase in one step (it splits runs and inserts the markers itself). Use scripts/comment.py for replies (--parent), or when the comment must carry all six comment parts.
  • Deleting comments: docx_comments.py delete removes the comment from comments.xml and its markers from the text only. It leaves the entries in commentsExtended.xml, commentsIds.xml and commentsExtensible.xml and does not delete replies, so a deleted comment that had replies leaves orphans behind. For comments written by comment.py, delete the replies too and remove the matching entries from those three files.
  • Accepting or rejecting changes: first search word/document.xml, word/header*.xml and word/footer*.xml (the script edits all of them) for revisions on paragraph marks (<w:pPr> → <w:rPr> → <w:ins>/<w:del>), on table rows (<w:trPr> → <w:ins>/<w:del>), moves (<w:moveFrom>, <w:moveTo>) and format changes (<w:rPrChange>, <w:pPrChange>). If none are present, docx_revisions.py works without LibreOffice and can also handle a single revision. If any are present, do not use it: it strips paragraph-mark and row markers without joining the paragraphs or removing the rows, leaves moves and format changes untouched, and its list then reports nothing left. Accept such documents with accept_changes.py; reject them in Word.
  • Validation: scripts/office/validate.py is the schema check and the only one that verifies tracked edits (--author). docx_validate.py is a quick structural check; a file can pass it and still contain XML Word rejects.
  • Merging fragmented runs: before editing word/document.xml by hand, use merge_runs.py (it also strips rsid attributes and <w:proofErr> markers, and never merges across a revision). Before docx_edit.py replace or docx_template.py on headers and footers, use docx_edit.py normalize, which covers them but stops at markers such as <w:proofErr>.
  • Template tokens and find/replace survive Word's run fragmentation: matched runs are collapsed and the replacement takes the first run's formatting.

Pitfalls:

  • Field codes (TOC, page numbers) are computed by Word or LibreOffice when the file opens; placeholder text shows until then.
  • A style must exist in the document before it is applied (KeyError otherwise). Built-ins such as Heading 1, List Bullet, List Number and Table Grid exist; declare custom styles in the create spec.
  • Separate List Number lists in one document may continue numbering instead of restarting.

Dependencies

docx (npm, preinstalled — install only if require('docx') fails) · pandoc · LibreOffice (soffice) · pdftoppm (Poppler) · Python 3.10+ with defusedxml and lxml for the scripts, plus python-docx for scripts/docx_*.py

Sources

scripts/docx_*.py, references/ and tests/ come from NousResearch/hermes-agent under the MIT License (LICENSE-HERMES.txt). The rest of this skill is covered by LICENSE.txt.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.