我需要通过 Office.js API 同时选择多个范围,就像在 MSWord UI 中按住 CTRL 键并突出显示多个不连续的段落一样,如下面的屏幕截图所示:
这种尝试是行不通的。它不是突出显示文档中单词“the”的前两个实例,而是突出显示第一个,然后突出显示第二个:
Word.run(function (context) {
// Set up the search options.
var options = Word.SearchOptions.newObject(context);
options.matchCase = false;
options.ignoreSpace = true;
options.ignorePunct = true;
options.matchWildcards = true;
var searchText = "the";
var searchResults = context.document.body.search(searchText, options);
context.load(searchResults);
return context.sync().then(function () {
searchResults.items[0].select();
searchResults.items[1].select();
});
});
不,所有 API 都不支持多项选择。即使用户使用 Ctrl+select 来执行此操作的能力也相对较新。该功能从未转移到 API 中。
API 最接近的功能是突出显示(或以其他方式格式化)Range
感兴趣的对象。 Word的对话框中有这样的功能,也可以使用COMAPI,但我没有找到 JS API 的等效项...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)