我正在尝试将Apps Script与Google Docs API结合使用,以在个人创建的子菜单中进行设置以更改文本颜色,具体取决于子菜单中选择的选项。有人可以给我一个大致的想法,让我知道如何获取特定段落的当前颜色并将其设置为其他颜色。
若要获取段落的当前前景色,请使用Method:Paragraph.getAttribute和Method:Paragraph.setAttribute设置前景色。
例:
码:
function myFunction() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
body.getParagraphs().forEach(par => {
var style = {};
if(par.getAttributes().FOREGROUND_COLOR == '#ff0000'){
style[DocumentApp.Attribute.FOREGROUND_COLOR] = '#0000ff';
}else if(par.getAttributes().FOREGROUND_COLOR == '#ff9900'){
style[DocumentApp.Attribute.FOREGROUND_COLOR] = '#008000';
}
par.setAttributes(style);
})
}
输出:
这是您可以使用的属性列表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句