以编程方式比较Word文档 [英] programmatically comparing word documents
问题描述
我需要比较两个Office文档,在这种情况下是两个Word文档,并提供一个差异,这与SVN中显示的内容有些相似.不能达到这个程度,但至少能够突出差异.
I need to compare two office documents, in this case two word documents and provide a difference, which is somewhat similar to what is show in SVN. Not to that extent, but at least be able to highlight the differences.
我尝试使用Office COM dll到此为止.
I tried using the office COM dll and got this far..
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);
有关进一步进行操作的任何提示?这将是一个点击率很高的Web应用程序.使用office com对象是正确的方法吗,或者我还有其他可以看的东西吗?
Any tips on how to proceed further? This will be a web application having a lot of hits. Is using the office com object the right way to go, or are there any other things I can look at?
推荐答案
我同意约瑟夫(Joseph)关于区分字符串的意见.我还建议您使用专用的差异化引擎(在此处找到几个):任何.NET的体面文本差异/合并引擎?),可以帮助您避免进行差异化时遇到的一些常规陷阱.
I agree w/ Joseph about diff'ing the string. I would also recommend a purpose-built diffing engine (several found here: Any decent text diff/merge engine for .NET?) which can help you avoid some of the normal pitfalls in diffing.
这篇关于以编程方式比较Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!