更新时间:2023-02-08 09:43:00
所以,这里是工作代码.显然,当我们插入文本时,返回了一个新的范围,我们需要使用该范围来插入书签.
So, here is the working code. Apparently, when we insertText, a new range is returned, we need to use that range to insertBookmark.
Word.run(function (context)
{
let range = context.document.getSelection();
return context.sync().then(function ()
{
let insertedTextRange = range.insertText(`Test Bookmark`, Word.InsertLocation.replace);
let uniqueStr = new Date().getTime();
let bookmarkName = `Test_BookmarkCode_${uniqueStr}`;
insertedTextRange.insertBookmark(bookmarkName);
});
});