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 xlsx files data of two different Excel files or multiple versions of the same file. We can easily compare two spreadsheets 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 to compare spreadsheet in this article:
- REST API and Python SDK to Compare Excel Files
- Compare Two Excel Files using Python
- Compare Multiple Excel Files in Python
- Get List of Changes in Python
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 in python on the cloud by following the simple steps given below:
- Upload the XLSX files to the cloud.
- Compare Uploaded Excel Files.
- 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 for Differences 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 excel documents and get results using the comparisons() method.
The following code sample shows how to compare excel sheets online using REST API in Python.
Download the Resultant File
As a result, the above code sample will save a newly created Excel file with spreadsheet comparison on the cloud. It can be downloaded using the following code sample:
Compare Multiple Excel Files in Python
We can also compare excel sheets for differences 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, excel sheet compare online 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 and compare data in excel sheets 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 compare data in two excel sheets for matches using REST API in Python.
Try Online
How to compare data from two excel sheets? Please try the following free online XLSX comparison tool to compare two excel sheets for matching data. This excel comparison tool compare 2 excel sheets online and is developed using the above API.
Conclusion
In this article, we have learned how to:
- compare two excel sheets and highlight differences 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 about how to compare excel spreadsheets, please feel free to contact us on the forum.