【发布时间】:2011-01-07 17:12:34
【问题描述】:
我有一个 Outlook 自动化。我想使用 Word 文档作为消息内容的模板。假设我有一些包含表格、颜色、大小等的格式化文本。现在我想将此内容复制/粘贴到 Outlook 消息对象中。
这里是一些示例代码(没有清理):
String path = @"file.docx";
String savePath = @"file.msg";
Word.Application wordApp = new Word.Application();
Word.Document currentDoc = wordApp.Documents.Open(path);
Word.Range range = currentDoc.Range(0, m_CurrentDoc.Characters.Count);
String wordText = range.Text;
oApp = new Outlook.Application();
Outlook.NameSpace ns = oApp.GetNamespace("MAPI");
ns.Logon("MailBox");
Outlook._MailItem oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.To = "mymail@someserver.com";
oMsg.Body = wordtext;
oMsg.SaveAs(savePath);
使用 Outlook/Word 2007,但 word 文件仍可能为 2000/2003 格式 (.doc)。
带有 .net 4.0 的 Visual Studio 2010(由于示例代码应该很明显)。
我习惯于互操作,我知道我目前只是在复制“纯文本”。我认为必须通过从 word 文档中检索 rtf/html 来完成...
有什么建议吗?
【问题讨论】:
-
你能展示一些你有的代码吗?
-
我没有通过剪贴板使用复制/粘贴!