以编程方式比较word文档

use*_*358 6 .net c# ms-office

我需要比较两个office文档,在这种情况下是两个word文档并提供差异,这有点类似于SVN中显示的内容.不是那么大,但至少能够突出差异.

我尝试使用办公室COM DLL,并得到了这个...

object fileToOpen = (object)@"D:\doc1.docx";
string fileToCompare = @"D:\doc2.docx";

WRD.Application WA = new WRD.Application();

Document wordDoc = null;

wordDoc = WA.Documents.Open(ref fileToOpen, Type.Missing, Type.Missing, Type.Missing, Type.Missing,      Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wordDoc.Compare(fileToCompare, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Run Code Online (Sandbox Code Playgroud)

有关如何进一步处理的任何提示?这将是一个具有大量点击的Web应用程序.使用office com对象是正确的方法,还是有其他我可以看的东西?

Pau*_*aul 1

我同意约瑟夫关于比较字符串的看法。我还推荐一个专门构建的比较引擎(可以在此处找到几个:任何合适的用于 .NET 的文本比较/合并引擎?),它可以帮助您避免比较中的一些常见陷阱。