Word Interop-停止默认程序对话框 - c#

我在程序中使用Microsoft Word Interop,并且试图创建Word应用程序,然后使用它来打开文档并阅读其具有的书签数量。

问题是,当我在并非每种文档类型的默认程序的机器上创建单词应用程序时(在测试中,我已将.rtf设置为使用写字板打开)时,会出现一个对话框,询问我是否要更改Word的默认程序设置。虽然此对话框仍然打开,但是我的代码正在尝试打开和访问文档的书签,这给了我一个COMException消息,即“呼叫被被呼叫者拒绝”。

我对互操作性上的MSDN文档进行了很好的浏览,但是找不到任何有用的东西。

我的问题是:制作新应用程序时,有什么方法可以阻止此对话框出现?可能告诉Word不要对此进行检查?

谢谢

参考方案

尝试这样的事情:

Microsoft.Office.Interop.Word.Application word= new Microsoft.Office.Interop.Word.Application();    
Document doc = word.Documents.Open(ref filename, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref obOpenAndRepair, ref oMissing, ref oMissing, ref oMissing);       
word.DisplayAlerts = WdAlertLevel.wdAlertsNone;

Havent已对此进行了测试,但应将WdAlertlevel设置为none,以免显示警报。
WDAlertLevel是Microsoft.Office.Interop.Word的枚举部分

C#使用Microsoft.Office.Interop.Excel读取Excel单元格值 - c#

我正在尝试提取Excel单元格值。我能够成功提取行值。我应该怎么做才能将每​​个单元格值从行中拉出?using Microsoft.Office.Interop.Excel; string pathToExcelFile = @"C:\Users\MyName\Desktop\Log.xls"; Application xlApp = n…

LeetCode题解212.word-search-ii

题目地址(212. 单词搜索 II) https://leetcode-cn.com/problems/word-search-ii/description/ 题目描述 给定一个二维网格 board 和一个字典中的单词列表 words,找出所有同时在二维网格和字典中出现的单词。 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平…

无法加载程序集。 。 Interop.Word版本14.0.0.0 - c#

我有一个用C#编写的WinForms应用程序,该应用程序会自动在Word中生成字母。该应用程序可以与安装了Office 2010的客户端计算机配合使用,但不能与安装了Office 2007的客户端计算机配合使用,但我收到以下错误消息-could not load file or assembly 'Microsoft.Office.Interop.…

C#Interop Delphi DLL - c#

我在Delphi“ a.dll”(没有源代码)中编写了第三方DLL。并且此DLL具有使用此签名的一种方法。function GetAny(pFileName: String): String; 我无法从c#进行互操作调用,因为'String type'在delphi中具有私有访问权限。因此,在delphi中构建另一个DLL来包装该调用。德尔福function…

LeetCode题解139.word-break

题目地址 https://leetcode.com/problems/word-break/description/ 题目描述 Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be seg…