Reputation: 146
I'm working on a Word add-in where the user can select a word. The word is then sent to a service which returns a list of laws with a name similar to the selected word. The user can then choose a law from the list and the selected word will then get a link to the specific law.
Right now I'm using the insertHtml method from the JavaScript API for Office.
range.insertHtml("<a href='linkToLaw'>selectedWord</a>", Word.InsertLocation.replace);
But when I do it this way the line breaks right after linked word and the following text is on the line below. enter image description here
I've been trying to use the insertOoxml method instead but without any luck.
So my question is: Is there an easy way to put a link on the selected text without changing the formatting of the surrounding text?
Upvotes: 1
Views: 1339
Reputation: 5046
I think your main issue is that you observe a line break inserted after your insertHtml
call. This is a bug that we fixed in the latest version of Office installed.
As an alternative, we are adding hyperlink functionality to ranges on the 1.3 requirement set for word. 1.3 is in preview right now, but you can try it here. Get a range then set a hyperlink with:
range.hyperlink="http://your.hyperlink.here"
Upvotes: 1