[英]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.提前致谢。
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 页插入。
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.不幸的是,我确认还不能使用 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.由于没有找到将幻灯片直接复制到新演示文稿的方法,所以我使用了以下流程。
DriveApp
.使用DriveApp
复制演示文稿。remove()
.使用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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.