Processing
 

Adding links in word using the JavaScript API for Office

19/09/2016 15:10#1

Joined at: 4 months ago

Post: 1

Thank: 0

Thanked: 0

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?

19/09/2016 17:20Top#2

Joined at: 4 months ago

Post: 11

Thank: 0

Thanked: 0

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" 
Similar articles

VBA regex matching over two lines

4 months ago - Reply: 1 - Views: 44

Table output to Word-2011 from Rstudio using knit

4 months ago - Reply: 0 - Views: 28

Write a Collection of paragraphs into a new document

4 months ago - Reply: 1 - Views: 70

how to write paragraphs without show to document

4 months ago - Reply: 1 - Views: 66

numericals in word macro

4 months ago - Reply: 1 - Views: 45

Can not find proofing tools

4 months ago - Reply: 0 - Views: 1

Possible values for <w:outlineLvl> in Word OOXML

4 months ago - Reply: 1 - Views: 7

C# restrict editing partial word paragraph

4 months ago - Reply: 2 - Views: 142

Macro translation Please (possible virus)

4 months ago - Reply: 1 - Views: 34

Doc/Docx Fastest Reading Method for Searching

4 months ago - Reply: 0 - Views: 1

Save embedded file / content from word

4 months ago - Reply: 0 - Views: 5

Counting words in Word document, including footnores

4 months ago - Reply: 1 - Views: 22

c# access extract word ole object

4 months ago - Reply: 1 - Views: 19

Using word wildcards to find unaccepted changes

4 months ago - Reply: 1 - Views: 45

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re