GroupDocs.Comparison for Cloud 是一种 REST API,能够让你的 Apex 应用程序比较两个相同格式的文档,找出它们之间的差异,生成结果文件,并允许你接受或拒绝检索到的更改。我们的文档比较 SDK for Apex 可轻松集成到你现有的应用程序中,使你的终端用户能够比较文档、电子表格、演示文稿、Microsoft Visio 图表、电子邮件以及许多其他格式的文件。
使用 GroupDocs.Comparison Cloud API,你可以比较文档并获取它们之间的更改列表。以下代码示例展示了如何检索源文件和目标 DOCX 文件之间的差异,并使用 Apex 将它们的差异获取为结果 DOCX 文件:
# TODO: Get your AppSID and AppKey at https://dashboard.groupdocs.cloud/#/apps (free registration is required).
# For complete examples and data files, please go to https://github.com/groupdocs-comparison-cloud/groupdocs-comparison-cloud-apex
String outPath = "result.docx",
sourceName = "source.docx",
targetName = "target.docx";
StorageApi storageApi = Utils.getStorageApiInstance();
// Upload files to Cloud Storage
File file = new File("src/main/resources/" + sourceName);
ResponseMessage storageresponse = storageApi.PutCreate("comparison/" + sourceName, null, null, file);
file = new File("src/main/resources/" + targetName);
storageresponse = storageApi.PutCreate("comparison/" + targetName, null, null, file);
ChangesApi changesApi = Utils.getChangesApiInstance();
PutChangesDocumentRequest request = new PutChangesDocumentRequest();
request.setRequest(GetComparisonRequest(sourceName, targetName));
request.setOutPath(outPath);
Link response = changesApi.putChangesDocument(request);
System.out.println(response);