首页 > 解决方案 > GoogleAppsScript | setPictureFill 在 Google 幻灯片中不起作用

问题描述

这是我的代码。我试图在 GoogleSlides 中通过 URL 设置背景,但是当我运行代码时,Google 返回TypeError: The setPictureFill function can not be found in the Page object。

var slide = SlidesApp.getActivePresentation().getSelection().getCurrentPage();
var img = 'https://media.giphy.com/media/9bTjZrytydVRK/giphy.gif';
slide.setPictureFill(img);

标签: google-apps-script

解决方案


在您的代码slide中是页面对象,但page对象没有setPictureFill()方法;因此出现错误。你需要的是一个PageBackground对象。尝试以下操作:

function my_fill() {
   var slide = SlidesApp.getActivePresentation().getSelection().getCurrentPage();
   var page_background = slide.getBackground();
   var img = 'https://media.giphy.com/media/9bTjZrytydVRK/giphy.gif';
   page_background.setPictureFill(img);
}

它成功地将动画空间 GIF 作为背景。


推荐阅读