Compare Spreadsheets - Asbjoedt/CLISC GitHub Wiki

Using Microsoft Spreadsheet Compare

You can use the program Microsoft Spreadsheet Compare to manually compare two spreadsheets. Spreadsheet Compare is bundled in Microsoft Office Professional Plus 2013, 2016, 2019 and Microsoft 365 Apps for enterprise.

You can also input two files and open the comparison from command line using the below code.

void Compare_Spreadsheets(string filepath_one, string filepath_two, string output_filepath)
{
    // Create script file
    string script_filepath = output_filepath + "\\script.txt";
    using (StreamWriter bcscript = File.CreateText(script_filepath))
    {
        filepath_one
        filepath_two
    }

    // Run Spreadsheet Compare
    int version = [YOUR OFFICE VERSION e.g. 13, 16, 19];
    Process app = new Process();
    app.StartInfo.FileName = $"C:\Program Files (x86)\Microsoft Office\Office{version}\DCF\SPREADSHEETCOMPARE.EXE";
    app.StartInfo.Arguments = $"\"@{script_filepath}";
    app.Start();
    app.WaitForExit();
    app.Close();

    // Delete script file
    File.Delete(script_filepath);
}

Using Beyond Compare

You can use the program Beyond Compare to compare two spreadsheets, though it only compares the cell values. This means any charts, pivot tables, images, formulas, data connections and so on are not compared.

Code example:

public void Compare_Workbook(string org_filepath, string conv_filepath)
{
    Process app = new Process();
    string? dir = null;
    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // If app is run on Windows
    {
        dir = Environment.GetEnvironmentVariable("BeyondCompare");
    }
    if (dir != null)
    {
        app.StartInfo.FileName = dir;
    }
    else
    {
        app.StartInfo.FileName = "C:\\Program Files\\Beyond Compare 4\\BCompare.exe";
    }
    app.StartInfo.Arguments = $"\"{org_filepath}\" \"{conv_filepath}\" /silent /qc=<crc> /ro";
    app.Start();
    app.WaitForExit();
    int return_code = app.ExitCode;
    app.Close();
    if (return_code == 0 || return_code == 1 || return_code == 2)
    {
        Console.WriteLine("--> Spreadsheets identical: True");
    }
    if (return_code == 12 || return_code == 13 || return_code == 14)
    {
        Console.WriteLine("--> Spreadsheets identical: False");
    }
    if (return_code == 11)
    {
        Console.WriteLine("--> Original file cannot be compared");
    }
    if (return_code == 100)
    {
        Console.WriteLine("--> Unknown error");
    }
    if (return_code == 104)
    {
        Console.WriteLine("--> Beyond Compare 4 trial period expired");
    }
}
⚠️ **GitHub.com Fallback** ⚠️