Word Track Changes

👤 elio-huang-15 📦 v1.0.0 ⭐ 4.3 ⬇️ 557 下载
📄 办公效率 免费

📖 技能介绍


name: word-track-changes description: Enable Microsoft Word's Track Changes (修订模式) on documents using native OOXML elements. Supports cross-run text matching and precise paragraph-level replacement. Use when agents need to modify Word documents with tracked changes that show up as insertions (green) and deletions (red strikethrough) in Word's Review pane. Handles real-world DOCX files where text is split across multiple w:t nodes.


Word Track Changes Skill

Enable native Microsoft Word Track Changes functionality using OpenXML. Handles real-world DOCX files where text is split across multiple <w:t> nodes.

When to Use

Use this skill when you need to: - Edit a Word document while preserving a visible record of changes - Show insertions as green underlined text - Show deletions as red strikethrough text - Allow users to accept/reject changes in Word's Review pane - Replace text that may be split across multiple <w:r> / <w:t> elements

Quick Start

1. Enable Track Changes on a Document

python ~/.openclaw/skills/word-track-changes/scripts/enable_tracking.py input.docx output.docx

2. Replace Text with Revision Mark

from track_changes import TrackChangesProcessor

p = TrackChangesProcessor("document.docx")
p.set_author("Agent")
p.replace_text_with_revision(
    old_text="existing text to replace",
    new_text="new text with revision mark"
)
p.save("output.docx")
p.cleanup()

3. Insert a New Paragraph with Revision Mark

from track_changes import TrackChangesProcessor

p = TrackChangesProcessor("document.docx")
p.set_author("Agent")
p.insert_paragraph_after(
    search_text="text before new paragraph",
    new_text="New paragraph shown as insertion."
)
p.save("output.docx")
p.cleanup()

4. Batch Multiple Revisions

from track_changes import batch_revisions

revisions = [
    {"type": "replace", "old": "old text 1", "new": "new text 1"},
    {"type": "insert_after", "search": "anchor text", "new": "inserted paragraph"},
]

batch_revisions(
    "input.docx",
    revisions,
    author="Agent",
    output_path="output.docx"
)

Key Capabilities

Capability Description
Cross-Run Matching Finds text even when Word splits it across multiple <w:t> nodes
Paragraph-Level Precision Only replaces the target text within its paragraph, preserving all other content
Format Preservation Copies existing run properties (<w:rPr>) for consistent font/style
Batch Revisions Apply multiple tracked changes in a single pass
Track Changes Settings Automatically enables trackRevisions in settings.xml

Technical Details

OOXML Elements Used

  • <w:ins> — Insertion mark (green, underlined)
  • <w:del> — Deletion mark (red strikethrough)
  • <w:delText> — Deleted text content

Architecture

DOCX (ZIP archive)
├── word/document.xml      ← Main content (modified with revision marks)
├── word/settings.xml      ← Track changes settings (updated if needed)
└── ...

The processor: 1. Unzips the DOCX into a temporary directory 2. Parses word/document.xml 3. Builds a paragraph-level text index to locate target text across split <w:t> nodes 4. Inserts <w:ins> / <w:del> at the exact position 5. Re-zips into a valid DOCX

Scripts Reference

All scripts are in scripts/ directory:

发现更多技能插件,请访问7w4.net。

Script Purpose
track_changes.py Core library with TrackChangesProcessor
enable_tracking.py CLI tool to enable track changes
insert_revision.py CLI tool to replace text with revision marks
delete_revision.py CLI tool to mark text for deletion
batch_revisions.py CLI tool for processing multiple revisions from stdin

Python API

TrackChangesProcessor(docx_path)

Main class for processing a DOCX file.

Methods

  • set_author(author) — Set the revision author name.
  • replace_text_with_revision(old_text, new_text) — Replace text inside a paragraph with tracked changes. Raises ValueError if old_text is not found.
  • insert_paragraph_after(search_text, new_text) — Insert a new paragraph after the paragraph containing search_text, marked as <w:ins>.
  • enable_track_changes() — Update word/settings.xml to enable track revisions.
  • save(output_path) — Write the modified DOCX.
  • cleanup() — Remove temporary files.

Helper Functions

  • enable_track_changes(input, output)
  • insert_text_with_revision(input, search, new, author, output)
  • mark_deletion(input, target, author, output)
  • batch_revisions(input, revisions, author, output)

Example: Real-World Report Update

See example_usage.py for a complete working example.

🤖 AI 评测

这是一款功能实用的Word修订追踪工具,能在文档中准确添加绿色插入和红色删除标记。文档说明清晰易读,示例丰富,命令行和Python两种使用方式都很便捷。核心算法能正确处理Word分词导致的文本拆分问题。少量不足是使用后需记得调用清理方法,批量操作失败时缺少回滚保护。总体而言质量可靠,适合需要保留修改记录的场景使用。

📊 多维度评分

适应性4.3
规范性4.1
有效性4.4
可靠性4
可信度5

📁 包含文件 (8 个)

📄 SKILL.md 4.7 KB
📄 _meta.json 137 B
📄 scripts/batch_revisions.py 771 B
📄 scripts/delete_revision.py 710 B
📄 scripts/enable_tracking.py 504 B
📄 scripts/example_usage.py 2.3 KB
📄 scripts/insert_revision.py 765 B
📄 scripts/track_changes.py 14.9 KB