Copying a slide from one Google Slides presentation into another
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 :
- Copy the presentation using
DriveApp
. - Open the copied presentation.
- 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.
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);