开发者

Copy Word format into Outlook message

I have an outlook automation. I would like to use a Word document as template for the message content. Lets say i have some formatted text containing tables, colors, sizes, etc. Now I'd like to copy/paste this content into an Outlook message object.

Here is some Sample Code (no cleanup):

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);开发者_StackOverflow
oMsg.To = "mymail@someserver.com";
oMsg.Body = wordtext;
oMsg.SaveAs(savePath);

Using Outlook/Word 2007, however the word files still mayb in 2000/2003 format (.doc).

Visual Studio 2010 with .net 4.0 (should obvious due to the samplecode).

I'm used to interop and I know that I am currently just copieing the "plain text". I think it has to be done via retreiving rtf/html from the word document...

Any suggestions?


The string you are reading the contents into is not going to be able to maintain the format. You will need to copy the selection by alternative means to retain the formatting.

One technique you can use is to save the document in html format - which will add the extra html word tends to add, read the html content into a string, i.e. this string will have the generated tags - , and then create an outlook mailItem and set the body format to html. - and set the body to the html that saving the word in html generated.


Office 2007 offers "MailEnvelope" feature, that can be used for my purpose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜