none
How to compare 2 word documents in C# with out Ms-office installed version RRS feed

  • Question

  • hai, 

    I want to compare 2 word documents in c# sideby side and get Different text or sentences in the word documents(.doc or .docx) as a report and the report can be highlighting the differences in side by side and am using following code

    Application wordApp = new Application();
    
                wordApp.Visible = true;
    
                object wordTrue = (object)true;
    
                object wordFalse = (object)false;
    
                object fileToOpen = @"D:\MyWorks\test1.doc";
    
                object missing = Type.Missing;
    
                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 = @"D:\MyWorks\test2.doc";
    
                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);
    
    
    
                Document doc = wordApp.CompareDocuments(doc1, doc2, WdCompareDestination.wdCompareDestinationNew, WdGranularity.wdGranularityWordLevel,
    
                    true, true, true, true, true, true, true, true, true, true, "", true);

    the above code giving follwing error

    Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

    please help me in this aspect and i want run this in system which does't contain ms-office installed version plese provide some gudilines 

    thanks

    sree

    Thursday, June 27, 2013 9:21 AM

Answers

  • Hi sree

    <<i want run this in system which does't contain ms-office installed version >>

    That's impossible as far as using the "interop" goes. You can only open documents within the Word application - it must be present for the code you show to work. There are no ifs, buts, or workarounds.

    The only possibility for comparing files (and they must be in the Office 2007 or later file format, not the old *.doc file format) would be to work with them as Open XML files. But you wouldn't be able to display them side-by-side as Word documents. A list of differences, yes, that would be possible if you're up to researching how the Word Open XML relates to the actual document the user sees and writing the necessary code.


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, June 27, 2013 2:32 PM
    Moderator

All replies

  • Hi sree

    <<i want run this in system which does't contain ms-office installed version >>

    That's impossible as far as using the "interop" goes. You can only open documents within the Word application - it must be present for the code you show to work. There are no ifs, buts, or workarounds.

    The only possibility for comparing files (and they must be in the Office 2007 or later file format, not the old *.doc file format) would be to work with them as Open XML files. But you wouldn't be able to display them side-by-side as Word documents. A list of differences, yes, that would be possible if you're up to researching how the Word Open XML relates to the actual document the user sees and writing the necessary code.


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, June 27, 2013 2:32 PM
    Moderator
  • hai cindy thanks for ur replay

    Monday, July 1, 2013 5:23 AM