2015-11-01 26 views
0

iam玩弄NetOffice包装并试图访问Outlook Mailitem的Word编辑器。NetOffice - 在Outlook MailItem中访问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。感谢您的帮助。

斯特凡

回答

-1

斯特凡,

为什么你需要使用NetOffice组装。我建议使用清晰的代码并立即发布底层的COM对象。完成使用后,请使用System.Runtime.InteropServices.Marshal.ReleaseComObject释放Outlook对象。如果您的加载项尝试枚举存储在Microsoft Exchange Server上的集合中的超过256个Outlook项目,这一点尤其重要。

mItem.GetInspector.WordEditor 

注意,检查员类的GetInspector方法返回一个应该被释放,以及督察类的一个实例。不要在单行代码中使用多个点。或者底层的COM对象将保持未发布状态。