使用Javascript将UI导航到MS Word文档中的唯一关键字(字符串、段落)

使用Javascript将UI导航到MS Word文档中的唯一关键字(字符串、段落),javascript,ms-word,office-js,office-addins,office-js-ux,Javascript,Ms Word,Office Js,Office Addins,Office Js Ux,我从后端接收带有首选位置的字符串以实现唯一性。请使用word API帮助我解决这个问题。使用这种方法,我可以搜索文档,但结果不是唯一的,UI也不能导航到关键字 export let FilterSearchDoc = (e, key, string) => { console.log("key pressed", key, string.string, string); Word.run(function (context) { var

我从后端接收带有首选位置的字符串以实现唯一性。请使用word API帮助我解决这个问题。使用这种方法,我可以搜索文档,但结果不是唯一的,UI也不能导航到关键字


export let FilterSearchDoc = (e, key, string) => {
    console.log("key pressed", key, string.string, string);
    Word.run(function (context) {
        var searchResults = context.document.body.search(string.string, { ignorePunct: true });
        context.load(searchResults, 'font');
        return context.sync().then(function () {
            console.log('Found count: ' + searchResults.items.length);
            for (var i = 0; i < searchResults.items.length; i++) {
                searchResults.items[i].font.color = 'black';
                searchResults.items[i].font.highlightColor = '#FFFF00'; //Yellow
                searchResults.items[i].font.bold = false;
            }
            return context.sync();
        });
    })
        .catch(function (error) {
            console.log('Error: ' + JSON.stringify(error));
            if (error instanceof OfficeExtension.Error) {
                console.log('Debug info: ' + JSON.stringify(error.debugInfo));
            }
        });
}

导出let FilterSearchDoc=(e,键,字符串)=>{
console.log(“按键”,key,string.string,string);
运行(函数(上下文){
var searchResults=context.document.body.search(string.string,{ignorePunct:true});
加载(搜索结果,'font');
返回context.sync().then(函数(){
log('Found count:'+searchResults.items.length);
对于(var i=0;i