DOCX Toolkit
Comprehensive document creation, editing, and analysis for Word documents (.docx) with support for tracked changes, comments, and formatting preservation.
Prerequisites
- pandoc (for text extraction)
- docx-js (npm) for creating new documents
- Python with defusedxml for editing
Instructions
Reading/Analyzing Content
Text Extraction with pandoc
pandoc --track-changes=all document.docx -o output.mdRaw XML Access (for comments, formatting, metadata)
python ooxml/scripts/unpack.py document.docx output_dirKey files:
word/document.xml,word/comments.xml,word/media/
Creating New Documents
Use docx-js (JavaScript):
import { Document, Paragraph, TextRun } from 'docx';
const doc = new Document({
sections: [{
children: [
new Paragraph({ children: [new TextRun("Hello World")] })
]
}]
});
Editing Existing Documents
- Unpack:
python ooxml/scripts/unpack.py file.docx dir - Edit XML files using Document library
- Pack:
python ooxml/scripts/pack.py dir file.docx
Redlining Workflow (Tracked Changes)
For legal, academic, business docs - use minimal, precise edits:
# Only mark text that actually changes
# Preserve original run's RSID for unchanged text
- Get markdown:
pandoc --track-changes=all file.docx -o current.md - Identify and group changes (3-10 per batch)
- Map text to XML, implement changes
- Pack and verify
Error Handling
- If password-protected, use decryption tools first
- Validate XML after each edit before packing
- Test tracked changes in Word to verify rendering
Notes
- Tracked changes:
<w:ins>(insertions),<w:del>(deletions) - Convert to images: soffice → PDF → pdftoppm
Source: anthropics/skills