How to Compare Excel files

So when you have two similar Excel workbooks or two versions of the same spreadsheet, what is the best thing to do first? That’s right, compare these files for differences, and then perhaps merge them into one file. Also, comparing workbooks will help you detect possible problems, such as incorrect tables, extra entries, inconsistent formulas, or improper formatting.GroupDocs.Comparison gives you many options for comparing a wide range of supported file formats, including Excel formats.

After the comparison, there are three colors on the resulting file that highlight the differences. You can also specify the colors yourself to identify the next difference:

  • Elements that were inserted in the first file. – blue, by default
  • Elements wich were deleted from the first file – red, by default
  • Elements that have changed their styles (font, color, etc.) – green, by default

The code sample to compare two Excel files:

string sourcePath = @"source.xlsx"; // NOTE: Path to the source Excel document 
string targetPath = @"target.xlsx"; // NOTE: Path to the target Excel document 
string resultPath = @"result.xlsx"; // NOTE: Path to the result Excel document       
            
using (Comparer comparer = new Comparer(sourcePath))
{
    comparer.Add(targetPath);
    CompareOptions compareOptions = new CompareOptions
   {
        DetectStyleChanges = true,
        DetalisationLevel = DetalisationLevel.High
   };
    comparer.Compare(resultPath, compareOptions);
}
Source / Target / Result Excel files
Source
Target
Result

As a result, you have an Excel file with highlighted changes, in which the deleted elements are marked with a font red, the added – in blue, and the modified – in green.

More resources

Advanced Usage Topics

To learn more about document comparison features, please refer to the advanced usage section.

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to compare your DOC or DOCX, XLS or XLSX, PPT or PPTX, PDF, EML, EMLX, MSG and other documents with free to use online GroupDocs Comparison App.

© Aspose Pty Ltd 2001-2022. All Rights Reserved.