Compare Excel Files using REST API in Python

Compare Excel Files using REST API in Python.

Excel is one of the most popular and widely used spreadsheet applications. It allows organizing, analyzing, computing, and storing data in tabular form. It is a very common requirement to compare data of two different Excel files or multiple versions of the same file. We can easily compare two or more Excel files to track changes and highlight the differences in a new file. In this article, we will learn how to compare Excel files using a REST API in Python.

The following topics shall be covered in this article:

REST API and Python SDK to Compare Excel Files

For comparing two or more XLSX files, we will be using the Python SDK of GroupDocs.Comparison Cloud API. It allows comparing ‎two or more documents of the supported formats and highlights the differences in a resultant file. Please install it using the following command in the console:

pip install groupdocs-comparison-cloud

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Compare Two Excel Files using Python

We can compare two Excel files on the cloud by following the simple steps given below:

  1. Upload the XLSX files to the cloud.
  2. Compare Uploaded Excel Files.
  3. Download the resultant file.

Upload the Excel Files

Firstly, we will upload the source and target XLSX files to the cloud using the following code sample:

As a result, the uploaded Excel files will be available in the files section of the dashboard on the cloud.

Compare Excel Files in Python

Now, we will compare the uploaded Excel files programmatically by following the steps given below:

  • Firstly, create an instance of the CompareApi.
  • Next, set the uploaded source and target XLSX input file paths.
  • Then, initialize the ComparisonOptions object and assign source and target files.
  • Next, set the output file path.
  • After that, create the ComparisonsRequest with ComparisonOptions as an argument.
  • Finally, compare files and get results using the comparisons() method.

The following code sample shows how to compare two Excel files using a REST API in Python.

source and target Excel files.
Source and target Excel files.
Compare Two Excel Files using a REST API in Python.
Compare Two Excel Files using a REST API in Python.

Download the Resultant File

As a result, the above code sample will save a newly created Excel file with changes on the cloud. It can be downloaded using the following code sample:

Compare Multiple Excel Files in Python

We can also compare multiple Excel files by following the steps given below:

  • Firstly, create an instance of the CompareApi.
  • Next, set the input source XLSX file path.
  • Then, set multiple target XLSX file paths.
  • Next, initialize the ComparisonOptions object and assign source and target files.
  • Then, set the output file path.
  • After that, create the ComparisonsRequest with ComparisonOptions as an argument.
  • Finally, compare files and get results using the comparisons() method.

The following code sample shows how to compare multiple Excel files using a REST API in Python.

Get List of Changes in Python

We can get a list of all the changes found during the comparison of Excel files by following the steps given below:

  • Firstly, create an instance of the CompareApi.
  • Next, set the input source XLSX file path.
  • Then, set the target XLSX file path.
  • Next, Initialize the ComparisonOptions object.
  • Then, assign source/target files and set the output file path.
  • After that, create the PostChangesRequest with ComparisonOptions object as an argument.
  • Finally, get results by calling the postChanges() method.

The following code sample shows how to get a list of changes using a REST API in Python.

Try Online

Please try the following free online XLSX comparison tool, which is developed using the above API. https://products.groupdocs.app/comparison/xlsx

Conclusion

In this article, we have learned how to:

  • compare two or more XLSX files in Python;
  • get a list of inserted and deleted items;
  • programmatically upload more than one XLSX files to the cloud;
  • download the XLSX file from the cloud.

Besides, you can learn more about GroupDocs.Comparison Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.

See Also