繁体   English   中英

Google 应用程序脚本:Google 幻灯片 - 将选定的幻灯片导出到新的幻灯片演示文稿

[英]Google apps script: Google Slide - exporting selected slides to a new slide presentation

我正在尝试找出一种将所选幻灯片导出到新幻灯片演示文稿的方法。 按住 ctrl 并在胶片中选择多张幻灯片(在屏幕截图示例中为幻灯片 2、3、4)后,如何仅将那些选定的幻灯片导出到新的幻灯片演示文稿?

我发现用户 Tanaike 回答的堆栈上的一个较旧的问题( Google 应用程序脚本:将活动幻灯片(谷歌幻灯片)导出为 PDF )导出活动幻灯片并将其转换为 PDF,但无论我做了什么来编辑脚本当我运行编辑过的脚本时,它只会复制一张幻灯片或返回错误。 我无法编辑代码以便导出所有选定的幻灯片。

预先感谢您的帮助。 复制我用作参考的 Tanaike 代码的一部分。

    function myFunction() {

  // 1. Retrieve the active slide.
  const s = SlidesApp.getActivePresentation();
  const activeSlide = s.getSelection().getCurrentPage().asSlide();

  // 2. Create a temporal Google Slides.
  const temporalSlides = SlidesApp.create("temporalSlides");

  // 3. Copy the active slide to the temporal Google Slides.
  temporalSlides.insertSlide(0, activeSlide);

  // 4. Delete the initial slide in the temporal Google Slides.
  temporalSlides.getSlides()[1].remove();
  temporalSlides.saveAndClose();
}

截屏

我相信你的目标如下。

  • 您想通过在 Google 幻灯片中选择几张幻灯片来将幻灯片复制到新的 Google 幻灯片中。
  • 您想使用 Google Apps 脚本实现此目的。

在您的情况下,以下示例脚本怎么样?

示例脚本:

在这种情况下,首先,请 select 来自活动 Google 幻灯片的幻灯片。 并且,请运行此脚本。 这样,选定的幻灯片就会复制到新的 Google 幻灯片中。 新的 Google 幻灯片将创建到根文件夹。

function myFunction() {
  // 1. Retrieve the selected slides.
  const s = SlidesApp.getActivePresentation();
  const pageRange = s.getSelection().getPageRange();
  if (!pageRange) return;
  const slides = pageRange.getPages();

  // 2. Create a new Google Slides.
  const newSlides = SlidesApp.create("newSlides");

  // 3. Copy the selected slides to the new Google Slides.
  slides.reverse().forEach(s => newSlides.insertSlide(0, s.asSlide(), SlidesApp.SlideLinkingMode.LINKED));

  // 4. Delete the initial slide in the new Google Slides.
  newSlides.getSlides()[slides.length].remove();
}
  • 当您选择无幻灯片时,不会运行此脚本。 请注意这一点。

  • 如果要将选中的幻灯片复制到现有的 Google 幻灯片中,请修改const newSlides = SlidesApp.create("newSlides"); const newSlides = SlidesApp.openById("###GoogleSlidesID###"); .

  • 当您要将复制的幻灯片链接到原始幻灯片时,请使用slides.reverse().forEach(s => newSlides.insertSlide(0, s.asSlide(), SlidesApp.SlideLinkingMode.LINKED)); .

参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM