【发布时间】:2021-09-17 12:53:08
【问题描述】:
我正在尝试使用 Google Apps 脚本替换 Google 幻灯片演示文稿中的形状颜色。
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("Not a box!!");
Logger.log(st);
Logger.log(shape.getText());
return;
}
}
catch(err) {
Logger.log("Not a Shape!!");
return; // not a shape!
}
var hexColor = shape.getFill().getSolidFill();
Logger.log(hexColor);
switch (hexColor){
case "#f16727ff": // Computer Science
shape.getFill().setSolidFill("#413c73ff");
case "#0b9faeff": // Information technology
shape.getFill().setSolidFill("#d90368ff");
case "#d71b55ff": // Digital Literacy
shape.getFill().setSolidFill("#aa968aff");
}
}
上面的代码永远不会运行替换代码(基本上永远不会到达Logger.log(hexColor);指令
【问题讨论】:
标签: google-apps-script google-slides-api