Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Created February 11, 2022 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/4aad973c1ef03e559b866f044598f157 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/4aad973c1ef03e559b866f044598f157 to your computer and use it in GitHub Desktop.
Compare Excel Files using REST API in Python

Learn how to compare Excel files using a REST API in Python:

The following topics shall be covered in this article:

  1. REST API and Python SDK to Compare Excel Files
  2. Compare Two Excel Files using a REST API in Python
  3. Compare Multiple Excel Files in Python
  4. Get List of Changes in Python
# This code example demonstrates how to compare two Excel files.
# Create necessary API instances
api_instance = groupdocs_comparison_cloud.CompareApi.from_keys(client_id, client_secret)
# Input source file
source = groupdocs_comparison_cloud.FileInfo()
source.file_path = "source.xlsx"
# Input target file
target = groupdocs_comparison_cloud.FileInfo()
target.file_path = "target.xlsx"
# Define comparison options
options = groupdocs_comparison_cloud.ComparisonOptions()
options.source_file = source
options.target_files = [target]
options.output_path = "result.xlsx"
# Create comparison request
request = groupdocs_comparison_cloud.ComparisonsRequest(options)
# compare
response = api_instance.comparisons(request)
# This code example demonstrates how to compare multiple Excel files.
# Create necessary API instances
api_instance = groupdocs_comparison_cloud.CompareApi.from_keys(client_id, client_secret)
# Input source file
source = groupdocs_comparison_cloud.FileInfo()
source.file_path = "source.xlsx"
# Input target 1 file
target1 = groupdocs_comparison_cloud.FileInfo()
target1.file_path = "target.xlsx"
# Input target 2 file
target2 = groupdocs_comparison_cloud.FileInfo()
target2.file_path = "target2.xlsx"
# Define comparison options
options = groupdocs_comparison_cloud.ComparisonOptions()
options.source_file = source
options.target_files = [target1, target2]
options.output_path = "result_multiple.xlsx"
# Comparison request
request = groupdocs_comparison_cloud.ComparisonsRequest(options)
# Compare
response = api_instance.comparisons(request)
# This code example demonstrates how to add your client Id and secret in the code.
client_id = '659fe7da-715b-4744-a0f7-cf469a392b73';
client_secret = 'b377c36cfa28fa69960ebac6b6e36421';
configuration = groupdocs_comparison_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
my_storage = ""
# This code example demonstrates how to download Excel file from the cloud.
# Create instance of the API
file_api = groupdocs_comparison_cloud.FileApi.from_config(configuration)
# Download file request
request = groupdocs_comparison_cloud.DownloadFileRequest("result.xlsx", "")
# Download file
response = file_api.download_file(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\comparison\\")
# This code example demonstrates how to get a list of changes found during comparison.
# Create necessary API instances
api_instance = groupdocs_comparison_cloud.CompareApi.from_keys(client_id, client_secret)
# Input source file
source = groupdocs_comparison_cloud.FileInfo()
source.file_path = "source.xlsx"
# Input target file
target = groupdocs_comparison_cloud.FileInfo()
target.file_path = "target.xlsx"
# Define comparison options
options = groupdocs_comparison_cloud.ComparisonOptions()
options.source_file = source
options.target_files = [target]
# Create post changes request
request = groupdocs_comparison_cloud.PostChangesRequest(options)
# post changes
response = api_instance.post_changes(request)
# Show
for change in response:
print("Change # " + str(change.id + 1) + "- Target Text: " + str(change.target_text) + ", Text: " + str(change.text) + ", Type: " + str(change.type));
# This code example demonstrates how to upload multiple Excel files to the cloud.
# Create instance of the API
file_api = groupdocs_comparison_cloud.FileApi.from_config(configuration)
# Upload sample files
for filename in glob.iglob("C:\\Files\\comparison\\upload\\*.xlsx", recursive=True):
destFile = filename.replace("C:\\Files\\comparison\\upload\\", "",1)
file_api.upload_file(groupdocs_comparison_cloud.UploadFileRequest(destFile, filename))
print("Uploaded file: "+ destFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment