Right now I am locating the words in a Word document by searching the term using
context.document.body.search(dict, { ignorePunct: true, matchCase: true, matchWholeWord: true });`
But I want to locate a word by its ordinal position in the Word document. I can't find the exact nth word.
Is it possible to do that?
The Office JS APIs don't (yet) have an equivalent to the Word COM object
Wordsthat lets you specify a "word" in a given range via an index value. Considering the fact that words are separated by a space you can get the entire text of a document, then split it to an array of "words".Once you know what that
nthword is, you can use the code you already have to search/find the range in the document.If the word could occur more than once then you may need to expand how the "split" is used in order to get the surrounding words so that the search can be more accurate.