I have some keywords already present in my Word document, which I want to be able to search and if found, insert Content Controls on that specific keyword. Something like -
let searchResults = context.document.body.search("[[]*[]]", { matchWildCards: true });
context.load(searchResults, 'text');
let contentControl = searchResults.items[0].text.insertContentControl();
Is there any way to do this? Any help would be appreciated. Thank you.
Yes. You can do that although your syntax isn't quite right. (It's the Range object that has the insertContentControl method, not text
. See insertContentControl. This will wrap the keyword in a rich content control.