文件比較
文件比較
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
}
}