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.
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.
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.
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);
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.
DriveApp
.remove()
.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();
}
}
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With