question

NilsLockean-6915 avatar image
0 Votes"
NilsLockean-6915 asked PhoebeYuan-2983 commented

Document.body.search filters out relevant hit

Our Word add-in needs to select a piece of text between startOffset A and endOffset B. Since the Office JS API doesn't provide a way to set a selection between start/end positions the body text, we use the search function. This works fine in most cases, however not when the same text is repeated multiple times.

Suppose i want to select "test test" in the document body "test test test". There are two occurrences of "test test" in this document body but the search API only finds one: "[test test] test". I need to select the second occurrence, "test [test test]", but can't seem to get the search API to find it.

Has anyone else found a solution for this issue?

office-js-dev
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@NilsLockean-6915 I'm checking with the team to see if they have any suggestions.

1 Vote 1 ·

Hi @NilsLockean-6915, which platform are you using?

0 Votes 0 ·

Hi @PhoebeYuan-2983! I am using the Office JS API on the following platforms:
- Word on iPad
- Word on Mac (Microsoft 365)
- Word 2016 or later on Mac
- Word 2019 or later on Mac
- Word on the web
- Word 2013 or later on Windows
- Word 2016 or later on Windows
- Word 2019 or later on Windows
- Word on Windows (Microsoft 365)

0 Votes 0 ·

Hey currently the search API can only recognize "[test test] test" inside "test test test" and it is aligned with search feature's design. For selecting a piece of text between startOffset A and endOffset B, you may consider posting a feature ask in m365dev-suggestions


0 Votes 0 ·

0 Answers