Docx

From flonat/flonat-research · View interactive version

Docx is an AI agent skill from the GitHub repository flonat/flonat-research. Create, read, edit, or convert Microsoft Word documents while preserving professional document structure. Use when a .docx file is a primary input or requested output, including tracked changes, comments, images, headings, page furniture, or polished reports and letters. Not for PDFs, spreadsheets,

How to use this skill

Skill file

DOCX creation, editing, and analysis

Overview

A .docx file is a ZIP archive containing XML files.

Quick Reference

| Task | Approach |

|------|----------|

| Read/analyze content | pandoc or unpack for raw XML |

| Create new document | Use docx-js — see CODE1 |

| Edit existing document | Unpack → edit XML → repack — see Editing below |

Converting .doc to .docx

uv run python scripts/office/soffice.py --headless --convert-to docx document.doc

Reading Content

# Text extraction with tracked changes
pandoc --track-changes=all document.docx -o output.md

# Raw XML access
uv run python scripts/office/unpack.py document.docx unpacked/

Converting to Images

uv run python scripts/office/soffice.py --headless --convert-to pdf document.docx
pdftoppm -jpeg -r 150 document.pdf page

Accepting Tracked Changes

uv run python scripts/accept_changes.py input.docx output.docx

Creating New Documents

Generate .docx files with JavaScript using docx-js. Install: npm install -g docx

Full code patterns (setup, page size, styles, lists, tables, images, hyperlinks, footnotes, tab stops, multi-column layouts, TOC, headers/footers): CODE0

Critical Rules for docx-js

Validation

uv run python scripts/office/validate.py doc.docx

Editing Existing Documents

Follow all 3 steps in order.

Step 1: Unpack

uv run python scripts/office/unpack.py document.docx unpacked/

Extracts XML, pretty-prints, merges adjacent runs, and converts smart quotes to XML entities. Use --merge-runs false to skip run merging.

Step 2: Edit XML

Edit files in unpacked/word/. Use "Claude" as the author for tracked changes and comments.

Use the Edit tool directly for string replacement. Do not write Python scripts.

Use smart quotes for new content:

| Entity | Character |

|--------|-----------|

| ‘ | ' (left single) |

| ’ | ' (right single / apostrophe) |

| “ | " (left double) |

| ” | " (right double) |

Adding comments:

uv run python scripts/comment.py unpacked/ 0 "Comment text with & and ’"
uv run python scripts/comment.py unpacked/ 1 "Reply text" --parent 0

Then add markers to document.xml.

Full XML patterns (tracked changes, comments, images): CODE0

Step 3: Pack

uv run python scripts/office/pack.py unpacked/ output.docx --original document.docx

Validates with auto-repair, condenses XML, and creates DOCX. Use --validate false to skip.

Common Pitfalls


Dependencies

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.