Outlook VSTO - 向WordEditor文档超链接添加新行 [英] Outlook VSTO - Add new line to WordEditor Document Hyperlink

查看:279
本文介绍了Outlook VSTO - 向WordEditor文档超链接添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码将超链接添加到我的MailItem

I am using following code to add hyperlinks to my MailItem

object link = url + System.Environment.NewLine;

Microsoft.Office.Interop.Outlook.MailItem currentMessage = MyAddIn.Application.ActiveInspector().CurrentItem;
Microsoft.Office.Interop.Word.Document doc = currentMessage.GetInspector.WordEditor;
Microsoft.Office.Interop.Word.Selection sel = doc.Windows[1].Selection;
doc.Hyperlinks.Add(sel.Range, ref result, ref missing, ref missing, ref link, ref missing);

虽然这会在Outlook MailItem中的新行上插入每个链接,但它还会在前面显示有线字符从第2行开始的每一行:

While this does insert each link on new line in Outlook MailItem, it also shows a wired character in front of each new line starting the 2nd line:

更新:
我也尝试将其添加到选择范围,例如

UPDATE: I have also tried adding it to selection range like

sel.Range.Text = System.Environment.Newline;

,但这根本不是添加新行。

, but that was not adding new line at all.

推荐答案

由于Outlook使用Microsoft Word编辑器撰写邮件,因此Word的对象模型适用于此处。代码中的 sel 表示Selection对象,它是消息中插入点的位置。在每个超链接插入后重新定义选择点,让Word知道链接的位置。

Because Outlook uses the Microsoft Word editor to compose messages, Word's object model applies here. sel in your code represents the Selection object, which is the location of the insertion point in the message. Redefining the selection point after each hyperlink insertion let's Word know where to put the link.

doc.Hyperlinks.Add(sel.Range, ref result, ref missing, ref missing, ref link, ref missing);
sel.EndKey(Word.WdUnits.wdLine); 
sel.InsertAfter("\n");
sel.MoveDown(Word.WdUnits.wdLine);

Environment.NewLine 应该得到为所使用的特定环境定义的换行符字符串,但显然在此处不起作用\ n。我想不出一种方法来连接\ n,URL工作为 link 是不是字符串 Hyperlinks.Add 要求它是对象

Environment.NewLine is supposed to get the newline string as defined for the particular environment being used, but clearly does not work here hence "\n". And I can't think of a way to make concatenating "\n" with the URL work as link is not a string and Hyperlinks.Add requires it to be an object.

这篇关于Outlook VSTO - 向WordEditor文档超链接添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆