Underline Color Word Web Add-in without Font Color

前提是你 提交于 2019-12-11 07:27:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!