文档比较
文档比较
POST /api/v1/embed/compare 像 Word 的“审阅 > 比较 > 比较文档”那样比较两个 .docx 版本,返回修订后的文档,其中每处差异都记录为修订(插入和删除,作者为 options.author),并附 JSON 摘要。在 Word 或嵌入的编辑器中打开即可逐条接受或拒绝;output_format 为 "json" 时只返回摘要。
curl https://mroffice.ai/api/v1/embed/compare \
-H "Authorization: Bearer $MROFFICE_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"original": { "url": "https://files.example.com/signed/msa-v1.docx" },
"revised": { "url": "https://files.example.com/signed/msa-v2.docx" },
"options": { "author": "Legal review" }
}'- 两份文档自带的修订先按“全部接受”处理(Word 也会这样询问)。
- 段落和表格按文本匹配;只在原文里的段落是删除的段落,只在修订稿里的是插入的段落;原位修改的段落逐词比较(options.granularity 为 "character" 时逐字比较)。
- 未变和插入的词保留修订稿的格式,删除的词保留原文的格式;被删除的图片连同其图像一并带入。
- 表格逐行、逐单元格比较;只在一个版本里的行是插入或删除的行。
- 不比较:仅格式变化、移动(显示为删除加插入)、页眉页脚、脚注和批注。
| 选项 | 含义 |
|---|---|
original、revised | { url | upload_id | data_base64, name? },都必须是 .docx。 |
options.author | 修订的作者(默认 MR Office)。 |
options.date | 修订日期,ISO 8601(默认现在)。 |
options.granularity | word(默认,与 Word 一致)或 character。 |
output_format | docx(默认)或 json。 |
result.comparison 统计插入、删除的处数(及词数),并列出每处修改及其位置;任务里保留前 200 条,json 输出包含全部(最多 1,000 条)。
"result": {
"filename": "msa-v2-comparison.docx",
"comparison": {
"identical": false,
"insertions": 4, "deletions": 3, "words_inserted": 11, "words_deleted": 7,
"author": "Legal review", "date": "2026-11-21T09:00:00Z", "granularity": "word",
"changes": [
{ "type": "replace", "location": "paragraph 3", "original_text": "30 days", "text": "45 days" },
{ "type": "delete", "location": "paragraph 9", "original_text": "This clause survives termination." },
{ "type": "insert", "location": "paragraph 12 (table row)", "text": "Support\tIncluded" }
],
"changes_truncated": false
}
}