Word Track Changes — Word 追踪 Changes
v1.0.0Enable Microsoft Word's 追踪 Changes (修订模式) on documents using native OOXML elements. Supports cross-运行 text matching and precise paragraph-level replacement. Use when 代理s need to modify Word documents with 追踪ed 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 追踪 Changes
安装命令
点击复制技能文档
Word 追踪 Changes 技能
Enable native Microsoft Word 追踪 Changes functionality using OpenXML. Handles real-world DOCX files where text is split across multiple nodes.
When to Use
Use this 技能 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 启动
- Enable 追踪 Changes on a Document
- Replace Text with Revision Mark
p = 追踪Changes处理器("document.docx") p.设置_author("代理") p.replace_text_with_revision( old_text="existing text to replace", new_text="new text with revision mark" ) p.save("输出.docx") p.清理up()
- Insert a New Paragraph with Revision Mark
p = 追踪Changes处理器("document.docx") p.设置_author("代理") p.insert_paragraph_after( 搜索_text="text before new paragraph", new_text="New paragraph shown as insertion." ) p.save("输出.docx") p.清理up()
- Batch Multiple Revisions
revisions = [ {"type": "replace", "old": "old text 1", "new": "new text 1"}, {"type": "insert_after", "搜索": "anchor text", "new": "inserted paragraph"}, ]
batch_revisions( "输入.docx", revisions, author="代理", 输出_path="输出.docx" )
Key Capabilities Capability Description Cross-运行 Matching Finds text even when Word splits it across multiple nodes Paragraph-Level Precision Only replaces the tar获取 text within its paragraph, preserving all other content 格式化 Preservation Copies existing 运行 properties () for consistent font/style Batch Revisions 应用ly multiple 追踪ed changes in a single pass 追踪 Changes 设置tings Automatically enables 追踪Revisions in 设置tings.xml Technical DetAIls OOXML Elements Used — Insertion mark (green, underlined) — Deletion mark (red strikethrough) — 删除d text content Architecture DOCX (ZIP 归档) ├── word/document.xml ← MAIn content (modified with revision marks) ├── word/设置tings.xml ← 追踪 changes 设置tings (更新d if needed) └── ...
The 处理器:
Unzips the DOCX into a temporary directory 解析s word/document.xml Builds a paragraph-level text 索引 to locate tar获取 text across split nodes Inserts / at the exact position Re-zips into a valid DOCX Scripts Reference
All scripts are in scripts/ directory:
Script Purpose 追踪_changes.py Core 库 with 追踪Changes处理器 enable_追踪ing.py 命令行工具 工具 to enable 追踪 changes insert_revision.py 命令行工具 工具 to replace text with revision marks 删除_revision.py 命令行工具 工具 to mark text for deletion batch_revisions.py 命令行工具 工具 for processing multiple revisions from stdin Python API 追踪Changes处理器(docx_path)
MAIn class for processing a DOCX file.
Methods 设置_author(author) — 设置 the revision author name. replace_text_with_revision(old_text, new_text) — Replace text inside a paragraph with 追踪ed changes. RAIses ValueError if old_text is not found. insert_paragraph_after(搜索_text, new_text) — Insert a new paragraph after the paragraph contAIning 搜索_text, marked as . enable_追踪_changes() — 更新 word/设置tings.xml to enable 追踪 revisions. save(输出_path) — Write the modified DOCX. 清理up() — 移除 temporary files. 辅助工具 Functions enable_追踪_changes(输入, 输出) insert_text_with_revision(输入, 搜索, new, author, 输出) mark_deletion(输入, tar获取, author, 输出) batch_revisions(输入, revisions, author, 输出) Example: Real-World 报告 更新
See example_usage.py for a complete working example.