c#:比较office文档,如果文件相同,只获得真/假结果
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c#:比较office文档,如果文件相同,只获得真/假结果相关的知识,希望对你有一定的参考价值。
我需要比较office文件(doc,docx,xls,xlsx,ppt,pptx),如果2个比较文件相同,则得到一个布尔值。
我找到了一个通过比较2生成结果文件的解决方案,但我不需要这个。
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
wordApp.Visible = false;
wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
object wordTrue = (object)true;
object wordFalse = (object)false;
object fileToOpen = @"D:Docs1.docx";
object missing = Type.Missing;
Microsoft.Office.Interop.Word.Document doc1 = wordApp.Documents.Open(ref fileToOpen,
ref missing, ref wordTrue, 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:Docs3.docx";
Microsoft.Office.Interop.Word.Document doc2 = wordApp.Documents.Open(ref fileToOpen1,
ref missing, ref wordTrue, 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);
Microsoft.Office.Interop.Word.Document doc = wordApp.CompareDocuments(doc1, doc2, WdCompareDestination.wdCompareDestinationNew, WdGranularity.wdGranularityWordLevel,
true, true, true, true, true, true, true, true, true, true, "", false);
有没有解决方案?
答案
找到你:
Microsoft.Office.Interop.Word.Document doc = wordApp.CompareDocuments(doc1, doc2, WdCompareDestination.wdCompareDestinationNew, WdGranularity.wdGranularityWordLevel,
true, true, true, true, true, true, true, true, true, true, "", false);
bool anyChanges = doc.Revisions.Count > 0;
以上是关于c#:比较office文档,如果文件相同,只获得真/假结果的主要内容,如果未能解决你的问题,请参考以下文章
word文档关闭后再打开出现“office open xml 错误”怎么办啊
java操作office和pdf文件java读取word,excel和pdf文档内容