← 返回
未分类

Word Track Changes

Enable Microsoft Word's Track Changes (修订模式) on documents using native OOXML elements. Supports cross-run text matching and precise paragraph-level replaceme...
在文档中启用 Microsoft Word 的修订模式(Track Changes),使用原生 OOXML 元素实现,支持跨运行文本匹配和精确的段落级替换。
elio-huang-15 elio-huang-15 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 294
下载
💾 0
安装
1
版本
#latest

概述

Word Track Changes Skill

Enable native Microsoft Word Track Changes functionality using OpenXML. Handles real-world DOCX files where text is split across multiple 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 / 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

CapabilityDescription
-------------------------
Cross-Run MatchingFinds text even when Word splits it across multiple nodes
Paragraph-Level PrecisionOnly replaces the target text within its paragraph, preserving all other content
Format PreservationCopies existing run properties () for consistent font/style
Batch RevisionsApply multiple tracked changes in a single pass
Track Changes SettingsAutomatically enables trackRevisions in settings.xml

Technical Details

OOXML Elements Used

  • — Insertion mark (green, underlined)
  • — Deletion mark (red strikethrough)
  • — 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 nodes
  4. Inserts / at the exact position
  5. Re-zips into a valid DOCX

Scripts Reference

All scripts are in scripts/ directory:

ScriptPurpose
-----------------
track_changes.pyCore library with TrackChangesProcessor
enable_tracking.pyCLI tool to enable track changes
insert_revision.pyCLI tool to replace text with revision marks
delete_revision.pyCLI tool to mark text for deletion
batch_revisions.pyCLI 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 .
  • 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.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-08 00:27 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,086 📥 814,839
ai-agent

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,385 📥 321,018
ai-agent

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,232 📥 268,314