TypeError:无法读取null的属性“ insertSlide”(第60行,文件“代码”)

时间:2020-02-13 04:44:22

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

非常感谢您提供有关如何修复此错误的指导。请参见以下给出错误的代码,

  // Copy a slide from another presentation and inserts it.
  var otherPresentation = SlidesApp.openById('1Fz6YWCyLIdHfDoonz-40qRlmnNCWwROIQjXqYwmRxS8');
  var currentPresentation = SlidesApp.getActivePresentation();
  var slide_v1 = otherPresentation.getSlides[0];
  var insertionIndex = 1;
  currentPresentation.insertSlide(insertionIndex, slide_v1);

1 个答案:

答案 0 :(得分:1)

感谢Tanaike和代码的一些更改-这已经解决。请在下面查看更新的代码。

  // Copy a slide from another presentation and inserts it.
  var otherPresentation = SlidesApp.openById('1Fz6YWCyLIdHfDoonz-40qRlmnNCWwROIQjXqYwmRxS8');
  var currentPresentation = SlidesApp.openById(documentId);
  var slide_v1 = otherPresentation.getSlides()[0];
  var insertionIndex = 1;
  currentPresentation.insertSlide(insertionIndex, slide_v1);

[0]之后使用getSlides()肯定有帮助

我删除了.duplicate(),因为它在模板上创建了重复项。