【发布时间】:2020-10-07 21:53:40
【问题描述】:
我有 11 个文件,每个文件有 140 多张幻灯片,并且没有一个形状与主题/母版相关联。我的目标是更改主字体并将所有红色文本(有很多红色文本)替换为黑色文本。
我成功地更新了主字体(感谢https://gist.github.com/dsottimano/20a50daded2128b4c86acb430cecba67),但在尝试为 ForegoundColor 写一些东西时遇到了问题。
我尝试修改此代码但无法使其工作:https://mashe.hawksey.info/2017/10/changing-the-color-of-all-links-in-google-slides-with-google-apps-script/
我需要用十六进制 #000000 替换所有使用前景色十六进制 #e04935 格式化的文本。
感谢有关使这项工作的任何提示!
这是我到目前为止所做的:
//original from: https://mashe.hawksey.info/2017/10/changing-the-color-of-all-links-in-google-slides-with-google-apps-script/
/**
* @OnlyCurrentDoc
*/
function changeTextColorforShapes(){
var deck = SlidesApp.getActivePresentation();
var slides = deck.getSlides();
slides.forEach(function(slide) {
// https://developers.google.com/apps-script/reference/slides/slide#getPageElements()
var elements = slide.getPageElements();
elements.forEach(function(element){
// https://developers.google.com/apps-script/reference/slides/page-element#getPageElementType()
var type = element.getPageElementType();
// Text boxes are 'SHAPES' (this code doesn't handle table cells)
if (type == "SHAPE"){
// https://developers.google.com/apps-script/reference/slides/text-range#getTextStyle()
var textStyle = element.asShape().getText().getForegroundColor();
// https://developers.google.com/apps-script/reference/slides/text-style#hasLink()
// Returns true if text is color #e04935 (https://www.color-hex.com/color/e04935) and changes text to color #ffffff (black)
if (ForegroundColor('#e04935')
textStyle.setForegroundColor('#ffffff');
}
});
});
}
【问题讨论】:
-
能否提供
but have come up short in trying to write something for ForegoundColor.和I tried to adapt this code and cannot make it work:的详细信息?我无法理解I need to replace all text formatted with foregroundcolor hex #e04935 with hex #000000.。可以问一下具体情况吗? -
我的幻灯片全都是红色文本(全部为十六进制 #e04935),我需要将所有这些文本更改为黑色。我想我可以使用这个代码的框架,因为它改变了所有带有链接的文本的颜色。我试过了,但我不知道我在做什么: var textStyle = element.asShape().getText().getForegroundColor(); if ForegroundColor('#e04935'){ textStyle.setForegroundColor('#000000');
-
感谢您的回复。
var textStyle = element.asShape().getText().getForegroundColor(); if ForegroundColor('#e04935'){ textStyle.setForegroundColor('#000000');是什么?你能展示你当前的脚本吗?如果可以,请将其添加到您的问题中? -
我在我的问题中添加了到目前为止的内容。显然我不知道我在做什么
-
感谢您的回复。我注意到已经发布了答案。我想尊重现有的答案。我认为它会解决您的问题。
标签: google-api google-slides-api google-slides