1

C# で VSTO を使用する Outlook アドインを開発しています。

ステップ 1: 予定探索用のリボンを作成します。リボン ボタンをクリックすると、ファイルが読み取られ、そのファイルが予定の本文に.rtf挿入されます。.rtf

 try
 {
 Outlook.Inspector insp = Globals.ThisAddIn.Application.ActiveInspector();
 Outlook.AppointmentItem meetingItem = insp.CurrentItem() as Outlook.AppointmentItem;
  if(meetingItem == null){
      MessageBox.Show("the meeting is null,create a meeting Item");
      meetingItem = (Outlook.AppointmentItem)insp.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);                   
    }
   if(meetingItem != null) {
    meetingItem.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
    object missing = System.Reflection.Missing.Value;
    Word.Application wordAppl;
    Word.Document wordDoc;
    Word.Selection wordSel = null;
    wordDoc = (Word.Document)insp.WordEditor;
    wordAppl = wordDoc.Parent as Word.Application;
    wordDoc.Activate();
   String path = "D://WordSendTest//template//en_US.rtf";
     String fileName = path.ToString();
     wordSel = (Word.Selection)wordAppl.Selection;
     wordSel.Range.Delete(ref missing, ref missing);
    object falseRef = false;
    wordSel.Range.InsertFile(fileName, ref missing, ref falseRef, ref falseRef, ref falseRef);
    }
   }
    catch (Exception ex)
     {
       MessageBox.Show("Robbin click error!"+ ex.ToString());
     }

ステップ 2: ユーザーが「送信ボタン」をクリックすると、ItemSend イベントをキャプチャします。

 private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);         
        }

ステップ 3: メール本文の末尾に「文字列テキスト」を挿入します。

  void Application_ItemSend(object Item, ref bool Cancel)
        {
            Outlook.Inspector insp = Globals.ThisAddIn.Application.ActiveInspector();
            Outlook.AppointmentItem meeting = insp.CurrentItem as Outlook.AppointmentItem;
            Word.Document wordDoc = insp.WordEditor as Word.Document;
            Word.Application wordApp = wordDoc.Parent as Word.Application;
            Word.Selection wordSel =(Word.Selection) wordApp.Selection;
            object missing = System.Reflection.Missing.Value;
            object units = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object findEnd = (object)"~-----~~-----~-----~-----~-----~-----~\r";
            object wholeWord = true;
            wordSel.HomeKey(ref units, ref missing);
            if(wordSel.Find.Execute(ref findEnd,ref missing,ref wholeWord,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing))
            {
            wordSel.MoveUp(ref missing,ref missing,ref missing);
            wordSel.TypeText("--=Head for Insert info =--\n");
            wordSel.TypeText("when user click the <send button>,the Tex info will be insert and show here \n");
            wordSel.TypeText("--=End for Insert info=--\n");
            }
            else {
               MessageBox.Show("not fonud the END tag");
            }
        }

問題: デバッグ モデルでは、送信ボタンがクリックされると、本文にテキストが正常に挿入されます。しかし、実際に送信されるメールは変わらず、「送信ボタン」をクリックする前と同じです。カレンダーで予定を開くと、本文は問題ありません。テキストはメール本文の最後に正常に挿入されます。

では、なぜメールが更新本文と共に送信されないのに、更新メール本文がカレンダーに保存されているのか、誰にもわかりません。

4

1 に答える 1

0

テキストを変更するコードは何ですか? いつ実行されますか?予定は送信されないことに注意してください。[送信] をクリックすると、Outlook は MeetingRequest オブジェクトを作成し、代わりに送信します。そのオブジェクトを変更できるのは、Application.ItemSend イベントを処理するときだけです。

于 2013-06-04T18:14:55.193 に答える