【问题标题】:Insert Images into an existing google slides template将图像插入现有的谷歌幻灯片模板
【发布时间】:2020-05-20 21:43:18
【问题描述】:

这是我当前的代码:

var NAME = "My favorite images";
var deck = SlidesApp.openById("1DKsiDGX9wwRbgP9WH2IJL2- 
    b1u1Q6jjz0JbrrKd_Fl4 ");

    /**
      * 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.BODY);
      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 = [
        "http://www.google.com/services/images/phone-animation- 
        results_2x.png ",
        "http://www.google.com/services/images/section-work-card- 
        img_2x.jpg ",
        "http://gsuite.google.com/img/icons/product-lockup.png",
        "http://gsuite.google.com/img/home-hero_2x.jpg"
      ];
      var [title, subtitle] = deck.getSlides()[0].getPageElements();
      title.asShape().getText().setText(NAME);
      subtitle.asShape().getText().setText("");
      images.forEach(addImageSlide);
    }

我不断收到错误找不到方法appendSlide((class))。 (第 12 行,文件“代码”) 我应该进行哪些更改才能插入图片的 URL,以便将它们插入现有的 google 幻灯片模板?

【问题讨论】:

    标签: google-apps-script google-slides-api google-slides


    【解决方案1】:

    根据文档here,没有名为SlidesApp.PredefinedLayout.BODY 的预定义布局。因此,您会收到该错误。例如,如果您将布局更改为空白,则此代码可以正常工作。

    请修改第 12 行,如下所示:

    var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BODY);
    

    var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK);
    

    【讨论】:

    • 是的,我发现这行得通。但是,我创建的模板中有自定义布局。如何使用这些布局?
    猜你喜欢
    • 1970-01-01
    • 2023-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多