none
Programatically compare two documents and get list of changes RRS feed

  • Question

  • Hi

    Is there any way to compare and retrieve the changes for two word document. I tried different options like the ones mentioned in below link, still I am not getting any way to get the changes for the document in the form of report. 

    The Interop WordDocument.Compare method generates the new file with changes however we are looking for only the changes done for the file. Also, the interop compare method always generates the new comaprision file even when there are no changes in the document. Please advice if there is any way to get the list of changes between two word documents (.docx)

    http://social.msdn.microsoft.com/forums/en-US/isvvba/thread/ab821d14-bfbc-4c08-b44b-7a5d293ecb2c

    http://msdn.microsoft.com/en-us/library/aa302294.aspx

    Thanks

    Vinod

    Tuesday, January 14, 2014 8:38 PM

Answers

  • Hi Vinod

    There is nothing built into Word that will give you a "list of changes". I'm not sure what you envision, as any "list" is necessarily out of context, so it might not be clear exactly what the change is/was. Content in a Word document is not so clearly structured that something like "XMLDiff" would work. And, in addition to changes in text, Word also tracks changes in formatting.

    Comparing two documents, as described in the link you provide, is the only thing built into the object model. You should be able to generate your own list by working through the Revisions collection of the result.

    It would also be possible for you to work with the files' Open XML content and do your own comparison. XMLDiff would probably even work for that, on a part-by-part basis (a document is a zip package of multiple files (=parts)).


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, January 15, 2014 4:41 PM
    Moderator

All replies

  • Hi Vinod

    There is nothing built into Word that will give you a "list of changes". I'm not sure what you envision, as any "list" is necessarily out of context, so it might not be clear exactly what the change is/was. Content in a Word document is not so clearly structured that something like "XMLDiff" would work. And, in addition to changes in text, Word also tracks changes in formatting.

    Comparing two documents, as described in the link you provide, is the only thing built into the object model. You should be able to generate your own list by working through the Revisions collection of the result.

    It would also be possible for you to work with the files' Open XML content and do your own comparison. XMLDiff would probably even work for that, on a part-by-part basis (a document is a zip package of multiple files (=parts)).


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, January 15, 2014 4:41 PM
    Moderator
  • Hi Cindy,

    Thanks for your answer. Problem with Interop Compare method is that it will always generate new file with differences which says Format changes even when there is no difference. We have a requirement to list this text has is changed / updated / removed or any format changes like font, alignment etc. Is there any option to get all these changes?

    Thanks

    Vinod

    Thursday, January 16, 2014 8:11 PM
  • As I mentioned before, you need to go through the document's Revisions collection. That will have properties which return information such as the type of change, the range of the change (the text), the formatting that was changed, etc. I doubt very much that a "format change" will be logged if there's no change in the format, but if there is none you can test for an empty string and ignore it.

    That's all you're going to get from the Word API.

    If that's not enough, then you have to work directly with the Word Open XML files.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, January 17, 2014 10:53 AM
    Moderator
  • I force almost the same topic few month ago. I was build a small addin compeering contest two Doc files.

    W_Porownywanie_wyrazow_small

    It turned out, however, with a built-in mechanismis is sufficient enough:/

    W_Porównaj_dokumenty_2007



    Oskar Shon, Office System MVP - www.VBATools.pl
    if Helpful; Answer when a problem solved

    Friday, January 17, 2014 11:55 AM