Outlook VSTO - 向 WordEditor 文档超链接添加新行
Outlook VSTO - Add new line to WordEditor Document Hyperlink
我正在使用以下代码将 hyperlinks 添加到我的 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 中的新行中插入了每个 link,但它还在从第 2 行开始的每个新行前面显示了一个有线字符:
更新:
我也试过将它添加到选择范围,如
sel.Range.Text = System.Environment.Newline;
,但这根本没有添加新行。
由于 Outlook 使用 Microsoft Word 编辑器撰写邮件,因此此处适用 Word 的对象模型。 sel
在你的代码中代表了Selection对象,也就是插入点在消息中的位置。在每次插入 hyperlink 后重新定义选择点,让 Word 知道将 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
不是 string
而 Hyperlinks.Add
要求它是一个object
.
我正在使用以下代码将 hyperlinks 添加到我的 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 中的新行中插入了每个 link,但它还在从第 2 行开始的每个新行前面显示了一个有线字符:
更新: 我也试过将它添加到选择范围,如
sel.Range.Text = System.Environment.Newline;
,但这根本没有添加新行。
由于 Outlook 使用 Microsoft Word 编辑器撰写邮件,因此此处适用 Word 的对象模型。 sel
在你的代码中代表了Selection对象,也就是插入点在消息中的位置。在每次插入 hyperlink 后重新定义选择点,让 Word 知道将 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
不是 string
而 Hyperlinks.Add
要求它是一个object
.