在处理多个版本的合同、研究论文或技术文件时,能够比较 Word 文档是至关重要的。使用自动化工具,您可以比较 2 Word docs,突出显示差异,并生成一份全面的报告,显示插入、删除或修改。这确保了准确性,节省了时间,避免了人工审核错误。

Word 文档比较的 API

该功能使开发人员能够在其 C# 应用程序中轻松比较 Word 文件。此强大的 API 识别 Word 文档之间的文本、格式和结构差异。通过 NuGet 安装 SDK:

NuGet\Install-Package GroupDocs.Comparison-Cloud -Version 23.10.0

现在,从 GroupDocs cloud Dashboard 获取您的客户端ID和密钥。

比较使用 C# 的 Word 文档

这里是如何使用 GroupDocs.Comparison 以编程方式比较 DOCX 文件的:

  1. 配置 API 凭据:
var config = new Configuration(clientId, clientSecret);
  1. 初始化 CompareApi:
var compareApi = new CompareApi(config);
  1. 定义源 Word 文件和目标 Word 文件:
var sourceFile = new FileInfo("source.docx");
var targetFile = new FileInfo("target.docx");
  1. 创建比较请求:
var request = new ComparisonRequest(sourceFile, targetFile, outputPath);
  1. 调用 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 工作流程非常有用。

  1. 生成 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"
  1. 执行文档比较:
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,您可以轻松比较两个 Word 文档并突出显示差异。无论您需要出于法律、商业还是学术用例比较 Word 文档,这个解决方案都能确保准确性和效率。与依赖手动审查或 Word 功能有限的比较文档不同,您可以将强大的文档比较集成到您的应用程序中。这使得比较 Word 文件、跟踪修订和确保文档完整性变得简单。

有用的链接

相关文章