在MS Word加载项中创建超链接 [英] Make hyperlink in MS Word Add-in
问题描述
有没有什么方法可以在MS Word加载项中添加指向所选文本的超链接?
is there any way to programmaticaly add an hyperlink to the selected text in a MS Word Add-In?
提前致谢。
推荐答案
下面的代码将所选文本转换为指向Microsoft站点的超链接:
The code below converts selected text into a hyperlink which points to the Microsoft site:
Microsoft.Office.Interop.Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range;
if (currentRange != null)
{
Microsoft.Office.Interop.Word.Hyperlink hp = (Microsoft.Office.Interop.Word.Hyperlink)
currentRange.Hyperlinks.Add(currentRange, "http://www.microsoft.com");
}
默认情况下,超链接的实际文本将是您选择的文字。如果您需要此文本具有不同的值,例如 - 实际的URL地址,您只需更改TextToDisplay属性:
The actual text of the hyperlink,by default, will be your selected text. If you need this text to be of different value, for instance - the actual url address, you can simply change the TextToDisplay property:
hp.TextToDisplay = "http://www.microsoft.com";
我不确定你的逻辑究竟有多动态,但我相信上面的例子会给出你正朝着正确的方向前进。
I'm not sure exactly how dynamic your logic needs to be but I believe the above example will give you a push in the right direction.
这篇关于在MS Word加载项中创建超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!