2014-11-06 74 views
0

我正在使用Outlook COM對象在PowerShell 2.0中創建一組約會,以在日曆上創建一組約會。我的代碼完全可以工作,但最終用戶請求將格式化的表格添加到約會的正文中。在嘗試了其他幾個選項之後,我最終使用了Mailitem.GetInspector.WordEditor來編輯正文。但是,我無法在不打開Outlook中的項目並保存的情況下保存正文。下面是相關代碼:將更改保存到mailitem的檢查員

$newCalenderItem = $folder.Items.Add() 
$newCalenderItem.Subject = $appt.Subject 
$newCalenderItem.Location = $location 
$newCalenderItem.Start = $d.AddHours($timeSlot.Time) 
$newCalenderItem.Duration = 60 * $timeSlot.Duration 
$newCalenderItem.BusyStatus = 2 
$newCalenderItem.ReminderSet = $false 
$newCalenderItem.Categories = $appt.Category 
$newCalenderItem.Body = "" 
if ($appt.BodyFile) { 
    $newCalenderItem.GetInspector.WordEditor.Range().InsertFile("C:\Body.rtf", "", $false, $false, $false) 

    #this doesn't save it 
    $newCalenderItem.GetInspector.WordEditor.Close([ref] -1) 
} 
#this saves everything but the body 
$newCalenderItem.Save() 

我已經試過GetInspector.Close()WordEditor.Close()WordEditor.Save()它會彈出一個另存爲對話框。有誰知道如何做到這一點?

回答

0

您將需要設置AppointmentItem.RtfBody屬性 - Outlook約會,任務和聯繫人使用RTF而不是HTML。你可以將你的RTF文件讀入一個不同的字節數組中傳遞給RtfBody屬性。

+0

我正在編輯MailItem,而不是預約。我試圖編輯RTFBody,但總是得到錯誤'異常設置「RTFBody」:「值不在預期範圍內。」所以我轉向使用MailItem的檢查器。 – 2014-11-07 16:54:35

+0

請顯示您的代碼。您是否創建了一個字節變量數組來保存數據? – 2014-11-08 17:38:51

0

我想到了自己挖掘檢查員的成員,並希望發佈答案,如果任何人發現這個搜索自己的問題。 您需要保存檢查員的CurrentItem而不是檢查員本身。

$newCalenderItem.GetInspector.CurrentItem.Save()