在處理多個版本的合約、研究報告或技術文件時,能夠比較 Word 文件是必不可少的。使用自動化工具,您可以比較 2 Word docs,突出顯示差異,並生成一份全面的報告,顯示插入、刪除或修改的內容。這能確保準確性,節省時間,並避免人工審查錯誤。
API for Word Document Comparison
該工具使開發人員能夠輕鬆地在他們的 C# 應用程序中比較 Word 文件。這個強大的 API 能夠識別 Word 文檔之間的文本、格式和結構差異。從 NuGet 安裝 SDK:
- 不僅僅是 Word 文件,該 API 還能比較 許多其他格式。
NuGet\Install-Package GroupDocs.Comparison-Cloud -Version 23.10.0
現在,從 GroupDocs cloud Dashboard 獲取您的客戶端 ID 和密鑰。
使用 C# 比較 Word 文件
這裡是如何使用 GroupDocs.Comparison 程式化地比較 DOCX 文件:
- 配置 API 憑證:
var config = new Configuration(clientId, clientSecret);
- 初始化 CompareApi:
var compareApi = new CompareApi(config);
- 定義源 Word 文件和目標 Word 文件:
var sourceFile = new FileInfo("source.docx");
var targetFile = new FileInfo("target.docx");
- Create a comparison request:
var request = new ComparisonRequest(sourceFile, targetFile, outputPath);
- 調用 API 在線比較文檔:
var response = compareApi.Compare(request);
// For more examples, https://github.com/groupdocs-comparison-cloud/groupdocs-comparison-cloud-dotnet
var config = new Configuration(clientId, clientSecret);
var compareApi = new CompareApi(config);
var sourceFile = new FileInfo("source.docx");
var targetFile = new FileInfo("target.docx");
var request = new ComparisonRequest(sourceFile, targetFile, outputPath);
var response = compareApi.Compare(request);
透過 cURL 比較 DOCX 檔案
另外,您可以使用和 cURL 命令在線比較 DOCX 文件。這對於自動化腳本和 CI/CD 工作流程非常有用。
- 生成 JWT 令牌:
curl -v "https://api.groupdocs.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
- 執行文件比較:
curl -v -X POST "https://api.groupdocs.cloud/v2.0/comparison/comparisons" \
-H "accept: application/json" \
-H "authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d "{ \"SourceFile\": { \"FilePath\": \"firstDoc.docx\" }, \"TargetFiles\": [ { \"FilePath\": \"secondDoc.docx\" } ], \"Settings\": { \"GenerateSummaryPage\": true, \"ShowDeletedContent\": true, \"ShowInsertedContent\": true, \"StyleChangeDetection\": true, \"InsertedItemsStyle\": { \"Bold\": true, \"Italic\": true, \"StrikeThrough\": true, \"Underline\": true }, \"DeletedItemsStyle\": { \"Bold\": true, \"Italic\": true, \"StrikeThrough\": true, \"Underline\": true }, \"ChangedItemsStyle\": { \"Bold\": true, \"Italic\": true, \"StrikeThrough\": true, \"Underline\": true }, \"WordsSeparatorChars\": [ \"string\" ], \"UseFramesForDelInsElements\": true, \"CalculateComponentCoordinates\": true, \"MarkChangedContent\": true, \"MarkNestedContent\": true, \"MetaData\": { \"Author\": \"Nayyer Shahbaz\", \"LastSaveBy\": \"Nayyer\", \"Company\": \"GroupDocs Cloud\" }, \"DiagramMasterSetting\": { \"UseSourceMaster\": true }, \"OriginalSize\": { \"Width\": 0, \"Height\": 0 }, \"HeaderFootersComparison\": true, \"SensitivityOfComparison\": 0 }, \"OutputPath\": \"comparisonOutput.docx\"}"
嘗試免費的在線文字比較工具
探索我們的免費 Document Comparison 應用程式,無需安裝任何軟體,即可在線識別兩個 DOCX 檔案之間的差異。

最終評論
使用 GroupDocs.Comparison Cloud SDK for .NET 或 cURL,您可以輕鬆比較 2 份 Word 文件並突顯差異。無論您需要比較 Word 文件用於法律、商業還是學術用途,此解決方案都能確保準確性和效率。與其依賴人工審查或 Word 的有限比較功能,您可以將強大的文件比較功能集成到您的應用程序中。這使得比較 Word 文件、跟踪修訂及確保文件完整性變得簡單。