问题描述
我目前正在创建一个 Word 插件,我想获得一个搜索词的位置,因为这个词可以在文档中出现多次,我想根据它们的位置来区分它们。
是否有解决方案或尚不可行?
这是我的功能:
function find() {
Word.run(function (context) {
var searchResult = context.document.body.search('SearchedWord',{ ignorePunct: true,matchWholeWord: true });
searchResult.load('items');
return context.sync().then(function () {
console.log('Found count: ' + searchResult.items.length);
var cpt = 0;
var id = 0;
searchResult.items.forEach(function (range) {
cpt = cpt + 1;
id = 'id'+cpt;
const contentControlledItem = range.insertContentControl();
contentControlledItem.appearance = "BoundingBox";
contentControlledItem.title = 'titleOk'+cpt;
setBinding(id,contentControlledItem);
});
// Synchronize the document state by executing the queued commands,// and return a promise to indicate task completion.
return context.sync();
});
})
}
先谢谢你!
解决方法
这在 Office JavaScript 库中是不可能的。另外,我不认为一个词有 X/Y 位置,因为一个词出现取决于页面大小、字体大小、边距等。