简体   繁体   English

将幻灯片从一个 Google 幻灯片演示文稿复制到另一个

[英]Copying a slide from one Google Slides presentation into another

I searched for a decent answer to this question but I couldn't come up with anything on SO so I thought I would post a new thread.我为这个问题寻找了一个不错的答案,但我想不出任何关于 SO 的东西,所以我想我会发布一个新线程。

I am trying to copy a single slide from Google Slides into another using the advanced Slides service with google apps script.我正在尝试使用带有 google 应用程序脚本的高级幻灯片服务将 Google 幻灯片中的一张幻灯片复制到另一张幻灯片中。

function myFunction() {
  var originalPresentation = Slides.Presentations.get('1Lqtwb5z8NcU4VVj8OOR11AJyET70tlRRj6QIhxsEZZg');

  var slideToCopy = originalPresentation.slides[3];

  var newSlides = Slides.Presentations.create({
    title: 'New Slidedeck',
    slides: [slideToCopy]
  })
}

This creates the slide deck with the title, but the slide isn't copied.这将创建带有标题的幻灯片组,但不会复制幻灯片。 The documentation indicates that you can pass an array of slides with the title, but nothing is copying.文档表明您可以传递带有标题的幻灯片数组,但没有复制。 Does it also need the masters and layouts?它还需要母版和布局吗? What am I doing wrong?我做错了什么? Thanks in advance.提前致谢。

Update at February 16, 2018 2018 年 2 月 16 日更新

At February 13, 2018 , the SlidesApp service was updated. 2018 年 2 月 13 日,更新了 SlidesApp 服务。 Now, copying slides can be achieved by the native methods.现在,可以通过本机方法实现复制幻灯片。

This sample script copies page 1 of srcPresentationId and inserts it as page 1 of the active presentation.此示例脚本复制srcPresentationId第 1 页并将其作为活动演示文稿的第 1 页插入。

Sample script :示例脚本:

var srcPresentationId = "### source fileId ###";
var copysrcSlideIndex = 0; // 0 means page 1.

var copydstSlideIndex = 0; // 0 means page 1.

var src = SlidesApp.openById(srcPresentationId).getSlides()[copysrcSlideIndex];
SlidesApp.getActivePresentation().insertSlide(copydstSlideIndex, src);

Reference :参考:

Original Answer原答案

Do you still look for the method for copying slides?您还在寻找复制幻灯片的方法吗? Unfortunately, I confirmed that copying using the Slides API cannot be done yet.不幸的是,我确认还不能使用 Slides API 进行复制。 But I thought of a workaround.但我想到了一个解决方法。

How about the following workaround?以下解决方法如何? In a recent Google update, I noticed that Class SlidesApp was added.在最近的 Google 更新中,我注意到添加了Class SlidesApp I used this.我用过这个。 Since I didn't find the method for copying a slide directly to a new presentation, I used the following flow.由于没有找到将幻灯片直接复制到新演示文稿的方法,所以我使用了以下流程。

Flow :流程:

  1. Copy the presentation using DriveApp .使用DriveApp复制演示文稿。
  2. Open the copied presentation.打开复制的演示文稿。
  3. Remove slides except for a slide you want to copy using remove() .使用remove()要复制的幻灯片以外的幻灯片。

Sample script :示例脚本:

function myFunction() {
  var srcSlides = 3; // A page number of slide that you want to copy. In this case, the top number is 1.

  var srcid = "1Lqtwb5z8NcU4VVj8OOR11AJyET70tlRRj6QIhxsEZZg";
  var dstid = DriveApp.getFileById(srcid).makeCopy().getId();
  var dstSlides = SlidesApp.openById(dstid).getSlides();
  dstSlides.splice(srcSlides - 1, 1);
  for (var i in dstSlides) {
    dstSlides[i].remove();
  }
}

References :参考资料:

If this was not useful for you, I'm sorry.如果这对你没有用,我很抱歉。

Maybe you're looking for this ?也许你正在寻找这个?

  var PresentationTEST = SlidesApp.openById(TEMPLATE_TEST);
  var PresentationTemplate = SlidesApp.openById(TEMPLATE_DEV);
  var slides = PresentationTemplate.getSlides();

  var slide = slides[0];
  var slide = PresentationTEST.appendSlide(slide);

暂无
暂无

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

相关问题 如何将幻灯片从一个演示文稿复制到另一个演示文稿? - How to copy a slide from one presentation to another? 使用 Google Apps 脚本从 Google 幻灯片演示文稿中删除一张幻灯片 - Delete one slide from a Google Slide Presentation using Google Apps Script 使用 Google Apps 脚本从母版幻灯片复制多张幻灯片 - Copying Multiple Slides from a Master Slide Desk using Google Apps Script Google 应用程序脚本:Google 幻灯片 - 将选定的幻灯片导出到新的幻灯片演示文稿 - Google apps script: Google Slide - exporting selected slides to a new slide presentation 谷歌幻灯片 - 通过表格添加带有 appscript 的幻灯片,新幻灯片将添加到演示文稿的末尾 - Google Slides - add slide with appscript through Sheets new slide to be added in the end of the presentation Google 幻灯片:从 Apps 脚本中选择一张幻灯片 - Google Slides: Select a slide from Apps Script 如何通过Google Apps脚本发布Google幻灯片演示文稿? - How to publish a Google Slides presentation from Google Apps Script? 将 google 表格中的 url 插入到 google 幻灯片演示文稿中 - insert urls from google sheets into a google slides presentation 在文本框中生成幻灯片列表,类似于在Google Presentation中指向特定幻灯片的超链接 - Generating a list of slides in a text box alike to hyperlinks to specific slide in Google Presentation Google 幻灯片中的交互式图表演示 - Interactive charts presentation in Google Slides
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM