Open Microsoft Word in "compare document" mode from command prompt
Asked Answered
D

3

19

I am working on a web project where client needs a functionality to first upload some MS Word document & then he can compare any two of the uploaded documents.

The idea I came up with is to first make the documents available using WEBDAV & then open both documents using command line with "Compare side by side" option. In this way he will be able to compare & modify two documents.

The problem is, I am not able to find any command which can be run from command prompt to open two documents in compare mode.

Also, if you know any other way to achieve this functionality then please share it with me.

Drumbeat answered 9/4, 2010 at 9:59 Comment(0)
S
9

There is a project to do this using a PowerShell script, ExtDiff: https://github.com/ForNeVeR/ExtDiff

Semiotic answered 11/9, 2017 at 18:14 Comment(0)
R
7

This may be an approach (for Visual Studio 2010)

I mixed together the two following links

http://social.msdn.microsoft.com/Forums/en-US/b7f4b480-ca1c-49a1-a2ea-b1d1cf5ad56b/how-do-you-compare-two-word-documents-in-c

http://msdn.microsoft.com/en-us/library/vstudio/ee342218%28v=vs.100%29.aspx

to a C# Console Project to which I added added the Reference: .NET --> Microsoft.Office.Interop.Word Version 14.0.0.0

here the source:

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
//using Office = Microsoft.Office.Core;
//using Microsoft.Office.Tools.Word;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Word.Application wordApp = new Word.Application();
            wordApp.Visible = false;
            object wordTrue = (object)true;
            object wordFalse = (object)false;
            object fileToOpen = @"C:\Temp\1.docx";
            object missing = Type.Missing;
            Word.Document doc1 = wordApp.Documents.Open(ref fileToOpen,
                   ref missing, ref wordFalse, ref wordFalse, ref missing,
                   ref missing, ref missing, ref missing, ref missing,
                   ref missing, ref missing, ref wordTrue, ref missing,
                   ref missing, ref missing, ref missing);

            object fileToOpen1 = @"C:\Temp\2.docx";
            Word.Document doc2 = wordApp.Documents.Open(ref fileToOpen1,
                   ref missing, ref wordFalse, ref wordFalse, ref missing,
                   ref missing, ref missing, ref missing, ref missing,
                   ref missing, ref missing, ref missing, ref missing,
                   ref missing, ref missing, ref missing);

            Word.Document doc = wordApp.CompareDocuments(doc1, doc2, Word.WdCompareDestination.wdCompareDestinationNew, Word.WdGranularity.wdGranularityWordLevel,
                true, true, true, true, true, true, true, true, true, true, "", true);

            doc1.Close(ref missing,ref missing,ref missing);
            doc2.Close(ref missing,ref missing,ref missing);
            wordApp.Visible = true;
        }

    }
}

TODO:

  • Replace 1.docx and 2.docx with strings from command line
  • maybe some Exception handling
Ripuarian answered 30/9, 2014 at 13:29 Comment(0)
M
2

I've looked at the list of command line switches and I didn't see anything relevant.

You could create a console application in .net that opens Word, loads in the 2 documents and switches Word to the compare documents viewmode. Instead of launching Word directly from the command line you launch your application.

Myeshamyhre answered 9/4, 2010 at 10:48 Comment(2)
Yes, seems to be a way but how can I automatically switch word in compare mode?Drumbeat
Use this function: msdn.microsoft.com/en-us/library/…Myeshamyhre

© 2022 - 2024 — McMap. All rights reserved.