【发布时间】:2011-07-01 13:17:18
【问题描述】:
我目前正在制作一个程序,需要在 Outlook 2007 和 Outlook 2010 中分析邮件消息。
在安装了办公套件的机器上,它可以正常工作。如果他们只有 Outlook,它似乎无法获取邮件,当我尝试获取文档的内容时,它给了我以下错误:
"Unable to cast COM object of type
'Microsoft.Office.Interop.Word.DocumentClass' to interface type
'Microsoft.Office.Interop.Word._Document'. This operation failed because the
QueryInterface call on the COM component for the interface with IID '{0002096B-0000-
0000-C000-000000000046}' failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
这是我用来获取消息的代码:
Office.Word.Document document = inspector.WordEditor as Office.Word.Document;
string body = document.Content.Text;
【问题讨论】:
-
为了避免异常,当然你应该在获取
document.Content.Text之前做if(document != null)检查。而且,我认为您将无法在没有安装 Word 的情况下使用 MS Word 对象库;因此是空引用。
标签: c# .net outlook-2007-addin