Document comparison is one of the most common requirements for today’s programming world. Whether it is to compare word files, compare excel files, PDF documents or even compare text files or any other document format, accuracy is the key factor while comparing.

Compare Files with Document Comparison API for .NET Developers

This article will give you the idea, how GroupDocs.Comparison facilitates programmers to compare any two or more documents in many ways. On-Premise APIs of GroupDocs.Comparison are currently available for .NET and Java, however, this article is inclined towards C# developers.

Compare Excel, Word Files or any Document in C#

GroupDocs.Comparison allows developers to compare two documents ([in fact more than 2][6]. The resulting document shows the changes between the two files in comparison. Below mentioned code shows how you can compare two excel files in just 3 lines of code in C#.

  1. Instantiate the [Comparer][7] object with the source document path.
  2. Call [Add][8] method to specify the target document path.
  3. Call [Compare][9] method.
  4. That’s it.
using (Comparer comparer = new Comparer(“source.xlsx”))

Comparing excel spreadsheets or Microsoft Word documents are just among the subset of comparisons that are supported by the .NET API of GroupDocs.Comparison. Below is the list of supported formats. You can visit the [documentation][10] to stay updated.

Compare two or more Spreadsheets or OneNote Documents in C#

After the release of GroupDocs.Comparison for .NET 20.2, the API now supports:

  • Comparison of more than two Microsoft Excel and OpenOffice spreadsheets (XLS, XLSX, ODS, CSV, …)
  • Compare multiple Microsoft OneNote documents.

The API already supports the comparison of multiple files for various document formats. Following code snippet shows how quickly, multiple excel files can be compared in C#.

using (Comparer comparer = new Comparer(“source.xlsx”)

Compare Documents from Stream in C#

As a programmer, you are not only allowed to compare documents that are available on local storage, in fact, we can compare documents from the stream.

  1. Just initialize the [Comparer][11] object with the source document stream.
  2. Call [Add][12] method and specify the target stream.
  3. Call [Compare][13] method
using (Comparer comparer = new Comparer(File.OpenRead(“source.docx”))

Compare Password Protected Word Documents / Excel Spreadsheet in C#

Password protection is common in the official documentation. Using the document comparison .NET API, it allows its users/developers to compare password-protected documents.

Just a little change in the code as compared to the code for comparing documents that are not password-protected. While loading the document, use [LoadOptions][14] to specify the document password. Below is the sample comparison code for your assistance.

using (Comparer comparer = new Comparer("source.docx", new LoadOptions() { Password = "1234" }))
    comparer.Add("target1.docx", new LoadOptions() { Password = "5678" });
    comparer.Add("target2.docx", new LoadOptions() { Password = "5678" });
    comparer.Add("target3.docx", new LoadOptions() { Password = "5678" });

Comparison of Documents with Specific Settings

One step ahead of just comparing, using the code similar to the mentioned below, you can compare multiple documents with your customized comparison settings.

[CompareOptions][15] provides you the opportunity to specify your comparison options like font styling for detected changes etc.

using (Comparer comparer = new Comparer(“source.docx”)
    CompareOptions compareOptions = new CompareOptions()
        InsertedItemStyle = new StyleSettings()
            FontColor = System.Drawing.Color.Yellow
    comparer.Compare(“result.docx”, compareOptions);

Compare Programming Language Files in C#

GroupDocs continuously increasing the support to compare more file formats. After the release v 20.2, you can now also compare JSON files using .NET API. Following are the programming language file formats that are recently added to the [supported document formats list][16]:

Let’s Talk

You can build your own application using the above-highlighted features. We will be delighted if you contact us on the [forum][17] to discuss, solving a problem, or share your feedback.

[6]: [7]: [8]: [9]: [10]: [11]: [12]: [13]: [14]: [15]: [16]: [17]: