Navigating the UI to unique keyword(string, paragraph) in MS Word document using Javascript

39 Views Asked by At

I'm receiving the string with preferred location from backend to achieve uniqueness. Please help me out with this using word API. Using this approach, i am able to search doc, but result is not unique and UI is also not navigating to the keyword.


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));
            }
        });
}
0

There are 0 best solutions below