【问题标题】:Delete one slide from a Google Slide Presentation using Google Apps Script使用 Google Apps 脚本从 Google 幻灯片演示文稿中删除一张幻灯片
【发布时间】:2018-10-14 18:40:59
【问题描述】:

我需要使用 Google Apps 脚本,而不是 API。

  • 我创建了一个空演示文稿
  • 似乎新创建的演示文稿默认总是包含一张空白幻灯片
  • 我在演示文稿中插入了一张幻灯片(取自其他 prez)。

-> 我想删除这张空幻灯片,以便演示文稿只包含我粘贴到其中的幻灯片。

我的代码:

var presentation = SlidesApp.create("my new presentation"); // creates an empty slide in the prez
presentation.insertSlide(0,slides.pop()); // a slide from a deck of slides collected elsewhere
presentation.getSlides().pop(); // here trying to delete the empty slide, doesn't work: the slide remains in the presentation.
presentation.saveAndClose();

【问题讨论】:

  • 我在评论中详细阐述了问题描述。

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


【解决方案1】:

你需要removeSlidepop() 只是将其从数组中删除并返回 Slide [] 中的最后一张幻灯片。

var lastSlide=presentation.getSlides().pop(); 
lastSlide.remove();

【讨论】:

  • 如何删除第 n 张幻灯片,而不是最后一张?
  • @user2988 你会使用.splice()。阅读 Mozilla 文档。
  • 应该是这样的吗? var nthSlide=presentation.getSlides().splice(nth,1); ?????
  • @user298 是的。那你应该remove()它。另请注意,幻灯片从 0(不是 1)开始计数。此外, splice() 返回一个数组。您需要删除该数组中的单张幻灯片。
  • 好的,这对我有用:for (i=lastColumn;i>1;i--){ slides[i].remove(); }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-19
  • 1970-01-01
  • 2019-01-23
  • 1970-01-01
  • 2018-03-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多