【问题标题】:How to get selection in a mailItem Body using outlook addin 2007 and VSTO c#如何使用 Outlook addin 2007 和 VSTO c# 在 mailItem Body 中获取选择
【发布时间】:2012-02-28 17:41:04
【问题描述】:

我想突出显示电子邮件正文中的一些文本,然后单击某些内容(工具栏按钮等)

Outlook.Application myApplication = Globals.ThisAddIn.Application;
              Outlook.Explorer myActiveExplorer = (Outlook.Explorer)myApplication.ActiveExplorer();

              Outlook.Selection selection = myActiveExplorer.Selection;

              if (selection.Count == 1 && selection[1] is Outlook.MailItem)
              {
                    Outlook.MailItem mail = (Outlook.MailItem)selection[1];

                    mail.Copy(); // currently opened mail

                    Outlook.MailItem mailItem = (Outlook.MailItem)
                 myApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                    mailItem.Subject = mail.Subject;
                    mailItem.To = mail.To;

                    mailItem.Body = ?????         // copy only selected text/images of user 

                    mailItem.Importance = Outlook.OlImportance.olImportanceLow;
                    mailItem.Display(true);
              }

在mailITem.Body 上,我只想从选定的邮件(// 当前打开的邮件)中粘贴用户的选定文本/图像。 我该如何实现它,我找不到粘贴方法。 选择的项目是什么,它存储到 sql server 数据库中

【问题讨论】:

    标签: sql-server-2008 c#-4.0 outlook-addin


    【解决方案1】:

    outlook无法获取邮件正文中选择的文本,所以将outlook转换为word编辑器,这样你就可以按照3个步骤操作了

    1. get the mail total body
    2. use the word editor based on the **microsoft.office.Interop.word** dll
    3.select the text and to store the any string 
    

    代码是先添加dll引用

    object oItem;
    Outlook.Application oApp=new Outlook.Application();
     Outlook.Explorer oExp=oApp.ActiveExplorer();
     Outlook.Selection oSel= oExp.Selection;
     for (i = 1; i <= oSel.Count; i++)
                    {
                        oItem = oSel[i];
            Outlook.MailItem oMail = (Outlook.MailItem)oItem;
    Outlook.Inspector inspector = oMail.GetInspector;
    
                // Obtain the Word.Document object from the Inspector object
                Microsoft.Office.Interop.Word.Document document = (Microsoft.Office.Interop.Word.Document)inspector.WordEditor;
    mailItem.Body = document.Application.Selection.Text;
    }
    

    我认为这是完全的帮助

    【讨论】:

      猜你喜欢
      • 2014-02-07
      • 2011-12-30
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 2017-11-18
      • 2011-05-10
      相关资源
      最近更新 更多