我们在谷歌幻灯片中有一个由其他人为我们创建的模板。当前布局名称与原始布局名称不同。
我们正在使用 Google App Script 将图像插入到模板中。但是,预定义的布局没有我们正在寻找的自定义布局。
这是一些代码。该代码有效,但它没有显示我们想要使用的布局。
var NAME = ("Price Changes, Earnings Revisions and F-GPE");
var deck = SlidesApp.openById("1bmDMb9OtmLzFT_ow-1j62tfsfDgEwsfY_-APz3fhLfs");
/**
* Creates a single slide using the image from the given link;
* used directly by foreach(), hence the parameters are fixed.
*
* @param {Date} link A String object representing an image URL
* @param {Date} index The index into the array; unused (req'd by forEach)
*/
function addImageSlide(imageUrl, index) {
var slide = deck.appendSlide(SlidesApp.PredefinedLayout.TITLE);
var image = slide.insertImage(imageUrl);
var imgWidth = image.getWidth();
var imgHeight = image.getHeight();
var pageWidth = deck.getPageWidth();
var pageHeight = deck.getPageHeight();
var newX = pageWidth/2. - imgWidth/2.;
var newY = pageHeight/2. - imgHeight/2.;
image.setLeft(newX).setTop(newY);
}
/**
* The driver application features an array of image URLs, setting of the
* main title & subtitle, and creation of individual slides for each image.
*/
function main() {
var images = [
"https://product.datastream.com/dscharting/gateway.aspx?guid=be998f9e-9a14-466c-b76b-fd7f551cccf1&action=REFRESH",
"https://product.datastream.com/dscharting/gateway.aspx?guid=64a0d7bd-599a-4c06-85fc-cfba7c09e26e&action=REFRESH",
"https://product.datastream.com/dscharting/gateway.aspx?guid=183c43b8-c149-49bb-a14e-50a92100b1b3&action=REFRESH",
];
var [title, subtitle] = deck.getSlides()[0].getPageElements();
title.asShape().getText().setText(NAME);
subtitle.asShape().getText().setText("GLOBAL SHARES WATCHLIST");
images.forEach(addImageSlide);
}