我正在使用NetOffice包装器,并试图访问Outlook邮件项的Word编辑器。
之前我用的是
MailItem mItem = (MailItem)inspector.CurrentItem;
Microsoft.Office.Interop.Word.Document docx = mItem.GetInspector.WordEditor;
Microsoft.Office.Interop.Word.Selection selected = docx.Windows[1].Selection;这是有效的。现在有了NetOffice,我试着
Word.Document docx = mItem.GetInspector.WordEditor;这告诉我对象不能转换为Word.Document。使用
Word.Document docx = mItem.GetInspector.WordEditor as Word.Document;告诉我们NetOffice.WordApi.Document不能被嵌入。
有人知道如何使用NetOffice访问WordEditor吗?谢谢你的帮助。
斯特凡
发布于 2019-07-30 02:02:16
如果有人像我一样再次遇到这种情况,他的问题的答案是在Visual Studio中选择NetOfficeWordApi引用,并将"Embed Interop Types“属性更改为False。
发布于 2015-11-02 01:40:40
斯特凡
为什么需要使用NetOffice程序集。我建议使用清晰的代码,并立即发布底层COM对象。使用完Outlook对象后,使用System.Runtime.InteropServices.Marshal.ReleaseComObject释放该对象。如果外接程序尝试枚举存储在Microsoft Exchange Server上的集合中的256个以上的Outlook项,这一点尤其重要。
mItem.GetInspector.WordEditor注意,Inspector类的GetInspector方法返回Inspector类的一个实例,该实例也应该被释放。不要在一行代码中使用多个点。或者基础COM对象将不会被释放。
https://stackoverflow.com/questions/33461522
复制相似问题