TypeError: Cannot read property 'insertSlide' of null (line 60, file “Code”)

为君一笑 提交于 2020-03-04 21:34:13

问题


Would be grateful for any guidance on how to fix this error. Please see below code which gives the error,

  // 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:


Thanks to Tanaike and some changes to the code - this has been solved. Please see updated code below.

  // 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);

Using [0] has definitely helped after the getSlides()

I have removed .duplicate() because it creates duplicates on the template.



来源:https://stackoverflow.com/questions/60200617/typeerror-cannot-read-property-insertslide-of-null-line-60-file-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!