Excel is one of the most widely used applications for data analysis, reporting, and financial management. Often, you need to compare two or more Excel workbooks to identify changes, validate updates, or track revisions. Doing this manually can be time-consuming and error-prone. Luckily, with the GroupDocs.Comparison Cloud SDK for .NET, you can programmatically compare Excel workbooks in C# and generate a new file with all differences highlighted.

In this tutorial, you will learn how to:

How to Set up Excel Comparison API

To compare Excel XLSX files, we’ll use the GroupDocs.Comparison Cloud SDK for .NEt. It allows you to compare spreadsheets, track changes, and save results in a single Excel workbook.

Install the SDK via NuGet:

Install-Package GroupDocs.Comparison-Cloud

Before running the following code snippet, please get your Client ID and Client Secret from the cloud dashboard.

Compare Two Excel Files using C#

You can compare two Excel files in C# by following these steps:

  1. Upload the source and target Excel workbooks.
  2. Run comparison using GroupDocs.Comparison API.
  3. Download the resulting file with highlighted changes.

Upload Excel Workbook

In order to perform the comparison operation, firstly, we need to upload the source and target XLSX files to the cloud storage using the following code sample:

Compare Excel Workbooks

Now use the following code snippet to compare two Excel workbooks. Once executed, the API generates a new Excel workbook containing highlighted changes between the two spreadsheets.

Compare Multiple Excel Workbooks in C#

The REST API also offers the capabilities to compare multiple Excel workbooks. Please follow the steps specified below.

  • Firstly, create an instance of the CompareApi.
  • Secondly, upload the input Excel workbooks into cloud storage.
  • Now, initialize the ComparisonOptions object where we define the input and resultant Excel workbooks.
  • Then, create an object of ComparisonsRequest where we pass ComparisonOptions object as an argument.
  • Finally, compare Excel workbooks using Comparisons() API call.
How to compare data in excel

Source and target Excel files.

Given below is a preview of resultant workbook generated after the comparison has been completed.

compare Excel Files in C#.

A preview of Excel comparison using REST API.

Get List of Changes in C#

The REST API also offers the capabilities to get a list of all the changes and compare data in Excel worksheets found during the comparison process.

  • 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.

Try Online

If you want to try the capabilities of API directly within a web browser, without writing a single line of code, you may consider using our free Online XLSX comparison tool. This Excel comparison tool compares 2 Excel worksheets online and returns the results.

compare excel files online

Conclusion

In this article, we demonstrated how to compare Excel workbooks in C# .NET, highlight differences between spreadsheets programmatically, compare multiple Excel files at once and how to extract a detailed list of changes in Excel files. With GroupDocs.Comparison Cloud SDK for .NET, you can automate Excel file comparison to improve accuracy, save time, and streamline data validation workflows.