Outlook 2007 - 如何将 RTF 文本插入约会项目



我在Outlook 2007中工作,我需要在AppointmentItem中插入RTF文本。我发现了一些帖子,声称您可以使用某某来做到这一点,但没有实际的代码显示如何做到这一点。到目前为止,我找到的最好的来源是 这里

我遵循了它,但最终没有任何东西入到约会项目中。

以下是我所拥有的:

Word.Document wd = AppointmentItem.GetInspector.WordEditor as Word.Document;
// *Assume that I have all the RTF text that I want to copy set up and ready in the clipboard and is ready to be inserted(copied) into the Appointment Item.
//This doesnt seem to work
wd.Content.Select();
wd.Content.Paste();
//This also doesnt seem to work
(AppointmentItem.GetInspector.WordEditor as Word.Document).Content.Select();
(AppointmentItem.GetInspector.WordEditor as Word.Document).Content.Paste();

因此,根据我所阅读和看到的内容,这就是您如何将RTF插入约会项目,但我仍然无法将任何东西放入AppointmentItem中。

现在说,如果我看这个变量:

(AppointmentItem.GetInspector.WordEditor as Word.Document).Content.Text;

但如果我看AppointmentItem.Text它仍然没有改变。

现在没有AppointmentItem.paste()AppointmentItem.text.paste()的函数,并且您无权访问约会项目中的 RTF 变量。

那么谁能告诉我我错过了什么? 如何粘贴到AppointmentItem或实际上将RTF文本放入AppointmentItem中。

谢谢。

问题是您没有为复制和粘贴指定选择。 复制和粘贴的工作方式完全类似于用户进行复制和粘贴,您必须先选择所需的范围。

尝试

wd.Sections[1].Range.Copy();
document.Range(0, 0).PasteAndFormat(Word.WdRecoveryType.wdPasteDefault);

您可以找到与此类似的一篇很好的文章Tom_Xu MSFT在名为"在Outlook.MailItem中加载.doc文件内容"的线程中写道。

对于任何试图使用 Office 2010、2013 解决此问题的人:

string sRtfBody = "{rtf1ansiansicpg1252deff0deflang1033{fonttbl{f0fnilfcharset0 Century Gothic;}}viewkind4uc1pardf0fs20 This course will help you appreciate the beauty of numbers in some ways that you may have never considered.par}";
Outlook.AppointmentItem aiMeeting = (Outlook.AppointmentItem)this._Outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
aiMeeting.RTFBody = Encoding.ASCII.GetBytes(sRtfBody);

最新更新