访问正在 Outlook 阅读窗格中编辑的文档

Ste*_*fan 6 c# outlook outlook-addin

我编写了一个简单的 VSTO 插件,当用户单击功能区栏按钮时,它会在电子邮件中插入超链接。这是一个代码示例:

    private void button1_Click(object sender, RibbonControlEventArgs e)
    {
        var context = e.Control.Context as Inspector;

        if (context != null)
        {
            if (context.IsWordMail())
            {
                var doc = context.WordEditor as Document;
                if (doc != null)
                {
                    var sel = doc.Windows[1].Selection;
                    doc.Hyperlinks.Add(sel.Range, "http://www.google.com", "", "", "Google", "");
                }
            }
        }
        else if (e.Control.Context is Explorer)
        {
            Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();

            if (explorer.Selection.Count == 1)
            {
                Microsoft.Office.Interop.Outlook.Selection itemSelection = explorer.Selection;
                var item = itemSelection[1] as MailItem;

                // get the instance of WordEditor in a reading pane?

            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

当在单独的窗口 ( ) 中编辑电子邮件时,此方法效果很好e.Control.Context is Inspector

如果正在回复/转发消息并且阅读窗格已打开,则编辑器将内联显示在阅读窗格中 ( e.Control.Context is Explorer)。

我不知道在这种情况下如何获取 的实例Document。我可以访问在资源管理器中选择的项目,但我无法弄清楚如何访问阅读窗格中显示的文档编辑器。

如果我将编辑器“弹出”到一个单独的窗口,它就可以正常工作(上下文更改为检查器)。

有没有办法访问直接在阅读窗格中编辑的电子邮件文档?


在Dmitry的大力帮助下,他为我指明了正确的方向,我发现 Explorer 类中有一个属性:Explorer.ActiveInlineResponseWordEditor它为您提供内联显示的编辑器。

Dmi*_*nko 1

  1. MailItem.GetInspector那你可以打电话Inspector.WordEditor。这在较新版本的 Outlook 中应该可以正常工作。Outlook 2016 也暴露了该Explorer.ActiveInlineResponseWordEditor属性。

  2. 您可以在Redemption中使用SafeExplorer对象(我是它的作者) - 它应该适用于所有版本的 Outlook,并且它公开属性(ReadingPane对象)。SafeExplorer.ReadingPane