首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >c#:比较办公室文档,如果文件相同,则得到正确/错误的结果

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

Stack Overflow用户
提问于 2018-07-09 09:51:42
回答 1查看 384关注 0票数 0

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

我找到了一个通过比较2生成结果文件的解决方案,但我不需要这个。

代码语言:javascript
复制
            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);

有什么解决办法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-09 09:58:20

为你找到的:

代码语言:javascript
复制
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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51242652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档