Skip to content

GroupDocs.Comparison for .NET - Demonstrates comparing Excel spreadsheets with basic, styled and content‑visibility options. Includes summary page generation.

Notifications You must be signed in to change notification settings

groupdocs-comparison/net-excel-comparison-sample

Repository files navigation

Compare Excel Spreadsheets using GroupDocs.Comparison for .NET

Product Page Docs Blog Free Support Temporary License

📖 About This Repository

This repository demonstrates comparing Excel spreadsheets using GroupDocs.Comparison for .NET. It provides ready‑to‑run code examples that highlight differences between spreadsheet versions, enabling developers to automate document comparison workflows. The examples are designed for .NET developers who need to detect changes in Excel files for data validation, reporting, or audit purposes.

The Challenge

Developers frequently need to track changes across multiple versions of Excel workbooks—whether for auditing financial data, validating report updates, or synchronizing collaborative edits. Manual inspection is error‑prone and does not scale, especially when dealing with large workbooks containing hundreds of rows and complex formulas. Moreover, stakeholders often require a visual representation of differences, custom styling for inserted/deleted cells, and a concise summary of changes.

Standard file‑diff tools treat spreadsheets as binary blobs, offering no insight into cell‑level modifications. Excel’s built‑in “Track Changes” feature is limited to shared workbooks and cannot be automated reliably in a CI/CD pipeline. Consequently, developers spend considerable time writing custom parsing logic or resort to ad‑hoc visual checks, which leads to inconsistent results and maintenance overhead.

GroupDocs.Comparison addresses these pain points by providing a high‑level .NET API that understands the Excel file format, detects cell‑level insertions, deletions, and modifications, and renders the differences directly in a new workbook. The library also supports custom styling, summary pages, and fine‑grained visibility control, allowing you to tailor the output to your exact reporting needs.

What is GroupDocs.Comparison?

GroupDocs.Comparison is a .NET library that enables developers to compare and highlight differences between a wide variety of document formats, including Excel spreadsheets. Key features include:

  • Compare any two documents and automatically highlight insertions, deletions, and modifications.
  • Generate a summary page that lists all detected changes.
  • Apply custom visual styles to inserted, deleted, and changed content.
  • Show or hide specific change types (e.g., hide inserted or deleted content).
  • Preserve original document layout while visualizing differences.

The library’s flexible API makes it straightforward to integrate document comparison into automated workflows, reporting systems, or desktop applications.

Prerequisites

  • .NET SDK – .NET 6.0 or later.
  • NuGet PackageGroupDocs.Comparison (latest version).
  • License – A valid GroupDocs.Comparison license file (temporary license available for evaluation).

Repository Structure

compare-excel-spreadsheets-dotnet/
│
├── Program.cs
├── GroupDocs.Comparison.Example.csproj
└── README.md
  • Program.cs – Contains all sample methods that demonstrate various comparison scenarios.
  • GroupDocs.Comparison.Example.csproj – Project file that references the GroupDocs.Comparison NuGet package and defines the build configuration.
  • README.md – This documentation file.

Code Examples

Applies the GroupDocs.Comparison license to enable full functionality of the comparison library.

This method initializes and applies the license file for GroupDocs.Comparison. Update the licensePath variable with the path to your license file. Without a valid license, the library runs in evaluation mode with limited capabilities.

string licensePath = "path to your license file";
License license = new License();
license.SetLicense(licensePath);

The snippet prepares the library for unrestricted use by loading a license, which is required for production deployments.

Performs a basic comparison between two Excel spreadsheets using default comparison settings, identifying and highlighting all differences including inserted, deleted, and modified cells.

This example demonstrates a straightforward comparison of two workbooks. It uses the default styling and options, producing a result file where all changes are highlighted with the library’s standard colors.

EnsureFileExists(sourcePath, "source Excel file");
EnsureFileExists(targetPath, "target Excel file");

using (var comparer = new Comparer(sourcePath))
{
    comparer.Add(targetPath);
    comparer.Compare(resultPath);
}

The code verifies the input files, creates a Comparer instance for the source workbook, adds the target workbook, and generates a comparison result with default visual cues.

Performs a styled comparison between two Excel spreadsheets with custom formatting options, applying distinct visual styles to different types of changes and generating a summary page for comprehensive change tracking and analysis.

This sample applies custom StyleSettings to inserted, deleted, and changed cells (green, brown, and firebrick fonts respectively) and adds a summary page. Deleted content is hidden to keep the output clean.

EnsureFileExists(sourcePath, "source Excel file");
EnsureFileExists(targetPath, "target Excel file");

var compareOptions = new CompareOptions
{
    InsertedItemStyle = new StyleSettings()
    {
        FontColor = System.Drawing.Color.Green,
        IsUnderline = true,
        IsBold = true,
        IsItalic = true
    },
    DeletedItemStyle = new StyleSettings()
    {
        FontColor = System.Drawing.Color.Brown,
        IsUnderline = true,
        IsBold = true,
        IsItalic = true
    },
    ChangedItemStyle = new StyleSettings()
    {
        FontColor = System.Drawing.Color.Firebrick,
        IsUnderline = true,
        IsBold = true,
        IsItalic = true
    },
    GenerateSummaryPage = true,
    ShowDeletedContent = false,
};

using (var comparer = new Comparer(sourcePath))
{
    comparer.Add(targetPath);
    comparer.Compare(resultPath, compareOptions);
}

The example shows how to tailor the visual appearance of differences and automatically produce a summary of changes for stakeholders.

Performs a comparison between two Excel spreadsheets while hiding inserted content, allowing you to focus on deletions and modifications without the visual clutter of new additions.

By setting ShowInsertedContent to false, this sample suppresses the display of any newly added cells in the result document, making deletions and modifications more prominent.

EnsureFileExists(sourcePath, "source Excel file");
EnsureFileExists(targetPath, "target Excel file");

var compareOptions = new CompareOptions
{
    ShowInsertedContent = false
};

using (var comparer = new Comparer(sourcePath))
{
    comparer.Add(targetPath);
    comparer.Compare(resultPath, compareOptions);
}

The code demonstrates a focused view on what was removed or altered, useful for audit scenarios where new additions are irrelevant.

Performs a comparison between two Excel spreadsheets while hiding deleted content, enabling you to focus on new additions and modifications without displaying removed elements.

Setting ShowDeletedContent to false removes any visual indication of deleted cells, highlighting only additions and changes.

EnsureFileExists(sourcePath, "source Excel file");
EnsureFileExists(targetPath, "target Excel file");

var compareOptions = new CompareOptions
{
    ShowDeletedContent = false
};

using (var comparer = new Comparer(sourcePath))
{
    comparer.Add(targetPath);
    comparer.Compare(resultPath, compareOptions);
}

This approach is handy when the primary interest lies in new data entered into the workbook.

Performs a comparison between two Excel spreadsheets while leaving gaps for deleted content, preserving the original document structure and layout to make it easier to identify where content was removed.

Enabling LeaveGaps retains empty cells where deletions occurred, keeping the spreadsheet’s layout intact and making the missing content immediately visible.

EnsureFileExists(sourcePath, "source Excel file");
EnsureFileExists(targetPath, "target Excel file");

var compareOptions = new CompareOptions
{
    LeaveGaps = true
};

using (var comparer = new Comparer(sourcePath))
{
    comparer.Add(targetPath);
    comparer.Compare(resultPath, compareOptions);
}

The snippet is useful for preserving column/row alignment when reviewing what was removed.

Performs a comparison between two Excel spreadsheets while hiding both inserted and deleted content, displaying only modified cells to provide a focused view of actual changes while maintaining document structure.

Both ShowInsertedContent and ShowDeletedContent are disabled, while LeaveGaps remains true to keep the layout. The result highlights only cells that changed value.

EnsureFileExists(sourcePath, "source Excel file");
EnsureFileExists(targetPath, "target Excel file");

var compareOptions = new CompareOptions
{
    ShowInsertedContent = false,
    ShowDeletedContent = false,
    LeaveGaps = true
};

using (var comparer = new Comparer(sourcePath))
{
    comparer.Add(targetPath);
    comparer.Compare(resultPath, compareOptions);
}

This configuration gives a clean diff that isolates modifications, ideal for change‑impact analysis.

Ensures that a file exists at the specified path, throwing a FileNotFoundException with a descriptive error message if the file is not found, to prevent comparison operations on non‑existent files.

The helper validates file presence before any comparison operation, providing a clear exception message that aids debugging.

if (!File.Exists(path))
{
    throw new FileNotFoundException($"The {description} was not found. Path:", path);
}

By guarding against missing inputs, this method safeguards the comparison workflow from runtime errors.

Related Topics to Explore

If you're working with Compare Excel Spreadsheets using GroupDocs.Comparison for .NET, the following articles may be helpful:

Keywords

GroupDocs.Comparison, .NET, Excel, spreadsheet comparison, document diff, compare Excel files, custom styling, summary page, hide inserted content, hide deleted content, leave gaps, license, NuGet, Comparer, CompareOptions, StyleSettings, FileNotFoundException, automation, document processing, change tracking, audit, data validation, reporting

About

GroupDocs.Comparison for .NET - Demonstrates comparing Excel spreadsheets with basic, styled and content‑visibility options. Includes summary page generation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages