javascript - 类型错误 : Cannot read property 'insertSlide' of null (line 60, 文件 "Code")

标签 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);

最佳答案

感谢 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);

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

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

关于javascript - 类型错误 : Cannot read property 'insertSlide' of null (line 60, 文件 "Code"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60200617/

相关文章:

javascript - 将文件流式传输到 html 视频播放器,因为它正在使用 fs 在 Electron 中下载

javascript - 根据属性值在 DOM 中查找元素

google-apps-script - 有没有办法在保留文本格式的同时替换 TextBox 形状内的文本?

javascript - 谷歌应用脚​​本: How to create slides on Google Slides and fill the placeholders in it with information from an array?

arrays - 使用 Google Apps 脚本从 Google 幻灯片演示文稿中删除一张幻灯片

javascript - 如何将转换添加到 Javascript document.getElementById ("myDIV").style.display = "none";

javascript - 选定范围识别

jquery - 如何确定 Google 表格窗口大小

google-apps-script - 一个脚本可以触发另一个脚本中的函数吗?

google-apps-script - 如何使用谷歌应用程序脚本阅读谷歌文档中的标题引用