我正在嘗試使用Google Apps Script替換Google Slide演示文稿中的形狀顏色。
function changeColors(){
const objectId = "#an-id#"; // Please set the object ID.
const slides = SlidesApp.openById(objectId).getSlides()。
slides.forEach(loopSlides)。
}
function loopSlides(slide){
var shapes = slide.getShapes();
if (shapes.length > 0) {
shapes.forEach(myFunction)。
}
}
function myFunction(shape) {
try{
var st = shape.getShapeType();
if (st != SlidesApp.ShapeType["RECTANGLE"] & &
st != SlidesApp.ShapeType["ROUND_RECTANGLE"] &&
st != SlidesApp.ShapeType["UNSUPPORTED"]){
Logger.log("不是一個盒子!!")。
Logger.log(st)。
Logger.log(shape.getText())。
return;
}
}
catch(err) {
Logger.log("不是一個形狀!!")。
return; //not a shape!
}
var hexColor = shape.getFill().getSolidFill() 。
Logger.log(hexColor)。
switch (hexColor){
case "#f16727ff"/span>: //計算機科學: //計算機科學.
shape.getFill().setSolidFill("#413c73ff") 。
case "#0b9faeff": //資訊技術: //資訊技術.
shape.getFill().setSolidFill("#d90368ff")。
case "#d71b55ff": //數字素養: //數字素養.
shape.getFill().setSolidFill("#aa968aff")。
}
上面的代碼將永遠不會運行替換代碼(基本上它永遠不會達到Logger.log(hexColor);指令
uj5u.com熱心網友回復:
當我運行你的代碼時,它達到Logger.log(hexColor);。
你代碼中的問題是,你的hexColor變數實際上是一個
注:
- 我使用String.toLowerCase()為你的
switch陳述句將rgb hex字串改為小寫 。
- 你的rgb十六進制字串是不正確的。(我洗掉了尾部的
ff)。RGB十六進制字串應該只由6個字符組成。 - 你的開關案例缺少
break,每個案例都有。如果你不包括break,形狀的顏色將總是被設定為最后的固體填充設定,即#aa968a。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/330555.html
標籤:
