【发布时间】:2018-12-06 02:42:31
【问题描述】:
我需要在我的插件中突出显示 Word 文档中的单词,当用户需要删除插件制作的突出显示时,应该可以只删除插件制作的突出显示。 不应删除用户制作的亮点。
现在我可以在我的插件中用红色突出显示单词,当用户想要删除突出显示时,即使用户突出显示也被删除。
下面是我的代码:
//Add highlights
return context.sync().then(function () {
// Queue a set of commands to change the font for each found item.
for (var i = 0; i < searchResults.items.length; i++) {
searchResults.items[i].font.color = 'red';
searchResults.items[i].font.underline = 'wave';
}
return context.sync();
});
//Remove highlights
Word.run(function (context) {
// Create a proxy object for the document body.
var body = context.document.body;
// Queue a commmand to clear the contents of the body.
body.load("font");
return context.sync().then(function () {
// Queue a set of commands to change the font for each found item.
body.font.color = 'black';
body.font.underline = 'None';
return context.sync();
})
.catch(errorHandler);
});
【问题讨论】:
-
如果这是我推荐的 COM API 以 书签 突出显示的范围。 JS API 不(还?)支持书签,因此最好将代码突出显示的范围放入 ContentControl 中。将内容控件的外观格式化为“隐藏”,这样它们对用户来说就不会“明显”。您还想将它们设置为“cannotDelete = true”。因此,当代码删除突出显示时,它只对突出显示文本时创建的内容控件之一中的内容这样做。移除高亮也会移除内容控件。
-
你能在 remove highlight 方法开始时重复原来的搜索,然后取消突出显示结果吗? IF 用户创建了符合搜索条件的新内容,并且 if 用户手动突出显示它,那么它也不会突出显示。这可以接受吗?
-
到目前为止,即使这样也更好@RickKirkham