Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 926
Jordan Rhea Avatar asked Oct 18 '17 04:10

Jordan Rhea


People also ask

Can I copy a slide from one Google slide to another?

Select the slide you want to copy. Click Edit on the menu bar. Select Copy. Click in the thumbnail pane where you want to paste the slide.


2 Answers

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 :

  • insertSlide(insertionIndex, slide)

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 :

  • Class SlidesApp : https://developers.google.com/apps-script/reference/slides/slides-app
  • remove() : https://developers.google.com/apps-script/reference/slides/slide#remove

If this was not useful for you, I'm sorry.

like image 155
Tanaike Avatar answered Nov 15 '22 10:11

Tanaike


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);
like image 44
ship Avatar answered Nov 15 '22 11:11

ship