简体   繁体   中英

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.

I am trying to copy a single slide from Google Slides into another using the advanced Slides service with google apps script.

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

At February 13, 2018 , the SlidesApp service was updated. 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.

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. But I thought of a workaround.

How about the following workaround? In a recent Google update, I noticed that Class SlidesApp was added. 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 .
  2. Open the copied presentation.
  3. Remove slides except for a slide you want to copy using 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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