How Claude Skills Handle OOXML Manipulation for Word and PowerPoint Files
Claude Skills provide a Python-based OOXML engine that automates complex Word and PowerPoint editing while injecting required schema attributes, validating against Office Open XML specifications, and preserving file integrity.
The ComposioHQ/awesome-claude-skills repository delivers a comprehensive framework for Claude Skills OOXML manipulation, enabling programmatic editing of .docx and .pptx files without manual XML wrangling. This engine abstracts the complexity of the Office Open XML specification through a layered architecture that manages file packaging, automated XML editing, and strict schema validation.
Architecture Overview
The implementation separates concerns into three distinct layers that handle document processing for both Word and PowerPoint files.
- File unpacking/packing: For DOCX,
ooxml.scripts.unpackandooxml.scripts.packmanage zip operations, while PPTX uses thepython-pptxlibrary'sPresentationclass to load and save zip archives. - XML editing: Word documents use the
DocxXMLEditorsubclass to manipulate DOM nodes directly, while PowerPoint relies on thepython-pptxobject model with helper functions likeapply_paragraph_propertiesandapply_font_propertiesto map JSON descriptions onto OOXML elements. - Schema validation: Both workflows share
BaseSchemaValidator(located invalidation/base.py) to verify XML parts against XSD schemas, check unique IDs, and validate relationship files and content-type declarations.
Word (DOCX) OOXML Manipulation Workflow
The DOCX implementation focuses on preserving tracked changes, comments, and strict OOXML compliance through automated attribute injection.
File Unpacking and Initialization
When opening a document, Document.__init__ copies the source folder into a temporary directory and establishes a writable baseline. The class provides lazy access to XML parts via dictionary-style indexing, such as doc["word/document.xml"], which returns a DocxXMLEditor instance for that specific part.
Automated Schema Compliance
The DocxXMLEditor class extends XMLEditor (defined in document-skills/docx/scripts/utilities.py) and overrides CRUD methods including replace_node, insert_before, insert_after, and append_to. Each modification triggers _inject_attributes_to_nodes, which automatically inserts:
- RSID attributes (
w:rsidR,w:rsidRDefault,w:rsidP) for revision tracking - Author and date metadata (
w:author,w:date) for insertions, deletions, and comments - Unique identifiers (
w:id) for tracked changes - Namespace declarations (
xmlns:w14,xmlns:w16du) when required by the schema
This guarantees every inserted element complies with the OOXML specification without manual attribute management.
Comment Infrastructure Management
The engine automatically maintains auxiliary comment files including comments.xml, commentsExtended.xml, commentsIds.xml, and commentsExtensible.xml. The _ensure_comment_relationships and _ensure_comment_content_types helpers update the [Content_Types].xml and relationship files to keep the document package consistent when adding annotations via add_comment.
Validation and Saving
Before persistence, Document.validate() executes DOCXSchemaValidator (inheriting from BaseSchemaValidator) and RedliningValidator. These validators check well-formed XML, unique IDs, namespace correctness, and relationship integrity. Finally, Document.save() writes the XML parts and repackages the zip archive while optionally re-running validation.
from document_skills.docx.scripts.document import Document
# Open an unpacked .docx folder (or let the class copy it)
doc = Document('workspace/unpacked', author='Alice', initials='A')
# Find the paragraph where we want the comment
para = doc["word/document.xml"].get_node(tag="w:p", line_number=42)
# Insert a comment spanning the whole paragraph
comment_id = doc.add_comment(start=para, end=para, text="Please revise this sentence.")
print(f"Created comment #{comment_id}")
# Persist the changes
doc.save('output/output.docx')
PowerPoint (PPTX) OOXML Manipulation Workflow
The PPTX implementation leverages the python-pptx object model while adding JSON-driven replacement capabilities and overflow detection.
Inventory and Analysis
The inventory.py script extracts a complete text inventory from presentations using inventory.extract_text_inventory. This walks every slide, collects text-containing shapes, and records formatting properties (paragraphs, runs, fonts, colors, bullets) into an InventoryData structure suitable for JSON serialization.
JSON-Driven Content Replacement
The replace.py script orchestrates modifications through apply_replacements. For each shape specified in the replacement JSON, the process:
- Clears existing content via
text_frame.clear() - Applies paragraph properties through
apply_paragraph_properties(alignment, bullets, spacing) - Applies font properties through
apply_font_properties(size, color, bold, italic) - Inserts new runs using OOXML-aware helpers like
OxmlElementto set low-level attributes such asa:buCharfor bullets andmarL/indentfor indentation
Validation and Overflow Detection
After modifications, the workflow saves a temporary copy, re-inventorys the content, and validates against BaseSchemaValidator (located at pptx/ooxml/scripts/validation/base.py). The detect_frame_overflow function ensures text does not exceed shape boundaries before final save via Presentation.save().
import json
from pathlib import Path
from document_skills.pptx.scripts.replace import apply_replacements
# Replace.json contains only the shapes we want to modify
replace_json = {
"slide-0": {
"shape-1": {
"paragraphs": [
{"text": "New title", "bold": True, "font_size": 24},
{"text": "Subtitle", "italic": True, "color": "#555555"}
]
}
}
}
Path('replace.json').write_text(json.dumps(replace_json, indent=2))
apply_replacements('input.pptx', 'replace.json', 'output/updated.pptx')
Shared Validation Infrastructure
Both document types rely on the BaseSchemaValidator defined in validation/base.py. This validator enforces XSD schema compliance for XML parts, unique ID constraints across the package, relationship file (.rels) integrity, and content-type declaration accuracy.
For DOCX files, DOCXSchemaValidator performs additional redlining checks through RedliningValidator to ensure tracked changes follow OOXML conventions. For PPTX files, the validator ensures that slide parts, layout relationships, and [Content_Types].xml entries remain consistent after python-pptx modifications.
Summary
- Three-layer architecture: File packaging, XML editing, and schema validation work together to preserve OOXML integrity for both document types.
- Automated attribute injection: The
DocxXMLEditorautomatically adds RSIDs, author metadata, and namespace declarations to Word documents during modifications. - JSON-driven PowerPoint editing: PPTX modifications use inventory extraction and replacement scripts to map high-level JSON descriptions onto OOXML elements while preserving formatting.
- Shared validation: The
BaseSchemaValidatorensures both DOCX and PPTX files maintain proper relationships, unique IDs, and namespace declarations according to Office Open XML specifications. - Source locations: Word logic resides in
document-skills/docx/scripts/document.pyandutilities.py, while PowerPoint handling is indocument-skills/pptx/scripts/replace.pyandinventory.py.
Frequently Asked Questions
What OOXML schema version does Claude Skills support?
The validators in validation/base.py check against standard Office Open XML XSD schemas. The DOCXSchemaValidator and shared BaseSchemaValidator ensure compliance with modern OOXML specifications, handling namespaces like xmlns:w14 and xmlns:w16du that Microsoft Office requires for tracked changes and extended features.
How does the engine handle tracked changes in Word documents?
The DocxXMLEditor class automatically injects revision tracking attributes through _inject_attributes_to_nodes. When you insert or modify content using methods like insert_before or replace_node, the system adds w:rsidR, w:rsidRDefault, and w:rsidP attributes, plus unique w:id values for each change, ensuring Word recognizes the modifications as tracked changes with proper author attribution.
Can Claude Skills modify PowerPoint files without breaking layouts?
Yes. The replace.py script includes overflow detection (detect_frame_overflow) that validates text fits within shape boundaries before saving. By using the python-pptx object model and OOXML-aware helpers like OxmlElement, the engine preserves existing formatting while allowing precise modifications to text content and styling attributes.
Where are the main entry points for developers integrating these skills?
For Word documents, import Document from document-skills/docx/scripts/document.py to access the high-level API. For PowerPoint, use apply_replacements from document-skills/pptx/scripts/replace.py to execute JSON-driven modifications. Both paths share validation utilities in their respective ooxml/scripts/validation/base.py files.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →