c#:比较office文档,如果文件相同,则得到正确/错误的结果

c#:比较office文档,如果文件相同,则得到正确/错误的结果,c#,compare,ms-office,C#,Compare,Ms Office,我需要比较office文件(doc、docx、xls、xlsx、ppt、pptx),如果两个比较文件相同,则只需得到一个布尔值 我找到了一个通过比较2生成结果文件的解决方案,但我不需要这个 Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application(); wordApp.Visible = false; w

我需要比较office文件(doc、docx、xls、xlsx、ppt、pptx),如果两个比较文件相同,则只需得到一个布尔值

我找到了一个通过比较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:\Docs\1.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:\Docs\3.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;

很高兴帮助您:)