I am developing an add-in for word.The main task is to populate the bookmarks in a document with data from the database.In office.js all i have found that a bookmark can be accessed as a range object and i am using "rangeObject.insertText(text, insertLocation)" method for inserting data into a bookmark.But the problem is 2nd parameter insertLocation value can be 'Replace', 'Start', 'End', 'Before' or 'After'.Which basically appends the data before or after the bookmark.like this - image 1 (current result using insertLocation value 'End')
using insertLocation value 'Replace' it replaces the whole bookmark and actually deletes the bookmark from the document!.So all i want is insert a text in the bookmark like this- image 2 (desired result)
Note: I have to read these bookmark value later.So no bookmark can be deleted.and i am using 1.4 beta version of the office.js api for purpose.
Here is my code-
Word.run(function (context) {
var doc = context.document;
//get the bookmark range by its name
var bookmarkRange = doc.getBookmarkRangeOrNullObject("cscasenumber01");
//insert a data
bookmarkRange.insertText("test data",'end');
// Synchronize the document state by executing the queued commands,
return context.sync();
}).catch(errorHandler);
thanks so much for using our preview APIs. You just found a bug on it! I just repro this behavior. And yes the semantics for before, start, end, after are very clear on the API.
We'll get this fixed, although I don't have a clear timeline on this. thank you.