小编Ste*_*fan的帖子

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

我编写了一个简单的 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 …
Run Code Online (Sandbox Code Playgroud)

c# outlook outlook-addin

6
推荐指数
1
解决办法
2280
查看次数

标签 统计

c# ×1

outlook ×1

outlook-addin ×1