问题
I am working on Word web addin OfficeJS, I wanna change my underline color to red. Is it possible to change the color of underline without affecting the font color ? Attached my code below:
Word.run(function (context) {
var searchResults = context.document.body.search(searchResult, { ignorePunct: true });
context.load(searchResults, 'font');
return context.sync().then(function () {
for (var i = 0; i < searchResults.items.length; i++) {
searchResults.items[i].font.color = 'red';
searchResults.items[i].font.underline = 'wave';
}
return context.sync();
});
})
回答1:
You have to first create a custom character style with the underline color set to red. Give the style a name. The following code works for me. "StyleZZ" is a character style which specifies an underline font with red underline color. In all other respects it is default font.
var searchResults = context.document.body.search(searchResult, { ignorePunct: true });
searchResults.load("style");
return context.sync().then(function () {
for (var i = 0; i < searchResults.items.length; i++) {
searchResults.items[i].style = "StyleZZ";
}
return context.sync();
});
Notice that you don't have to load everything on the searchResults
object, only the style
property.
来源:https://stackoverflow.com/questions/50922156/underline-color-word-web-add-in-without-font-color