Search code examples
gitpowerpointgit-mergeoffice-automation

Configure PowerPoint Compare & Merge in git


PowerPoint has a feature to compare 2 PowerPoint files in the UI. It's in the Review ribbon and then Compare.

I'd like to configure git to be able to compare & merge 2 PowerPoint files from the commandline, pop open PowerPoint, resolve the changes and save.

But unfortunately I can't seem to find a way to open PowerPoint in the compare mode from without many clicks. Anyone happen to know the right way to invoke powerpnt.exe to open in this magic mode?


Solution

  • After ample research, the conclusion is, while PowerPoint does support a merge mode, there is no way to open it up in that mode with a command-line parameter.

    enter image description here

    But the API to merge documents is available in the COM object model and thus also from .NET through the Primary Interop Assemblies.

    I ended up writing a small open-source project which acts as a proxy between the command-line and PowerPoint to launch and merge files. (currently still a work in progress and rough):

    https://github.com/jessehouwing/ppt-diffmerge

    ppt-diffmerge-tool --local="$LOCAL" --remote="$REMOTE" --base="$BASE" --output="$RESULT" 
    

    Core piece of code:

    
    PowerPointApplication app = null;
    Presentation presentation = null;
    
    try
    {
        app = new PowerPointApplication();
        app.PresentationCloseFinal += App_PresentationClose;
    
        if (!string.IsNullOrWhiteSpace(Output))
        {
            File.Copy(Local, Output, true);
            Local = Output;
        }
    
        presentation = app.Presentations.Open(Local);
    
        if (string.IsNullOrWhiteSpace(Base))
        {
            presentation.Merge(Remote);
        }
        else
        {
            presentation.MergeWithBaseline(Remote, Base);
        }
    
        handle.WaitOne();
    }
    finally
    {
        Marshal.ReleaseComObject(presentation);
        Marshal.ReleaseComObject(app);
    }
    return 0;
    

    And it's crazy, even supports 3-way merges!