使用Google Apps脚本从主幻灯片台复制多张幻灯片

编程入门 行业动态 更新时间:2024-10-11 01:18:40
本文介绍了使用Google Apps脚本从主幻灯片台复制多张幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个代码来替换Google幻灯片上的占位符.该项目的起点是Google表单.提交Google表单后-谷歌表单中的相关数据就会输入到Google幻灯片模板中.参见下面的代码.我希望在表单上创建一个问题,使人们可以选择要包含的多张幻灯片(例如,10张中有2张凭据幻灯片)

I have created a code which replaces placeholders on google slides. The starting point of this project is a google form. Once the google form has been submitted - then the relevant data from google form is entered on the google slides template. See below code. I am looking to create a question on the form where people will be able to select multiple slides to be included (2 Credential slides for example out of 10)

function PoD() { SpreadsheetApp.getActiveSpreadsheet().getSheetByName("A-PoD").activate(); var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var lr = ss.getLastRow() for (var i =2;i<lr;i++){ if(ss.getRange(i, 1).getValue()){ //Make a copy of the template file var documentId = DriveApp.getFileById('1REHMrl6kfzXbgSipvBDkNitkfsM8tJsUSAICggxNsHw').makeCopy().getId(); var Name_of_programme = ss.getRange(i, 2).getValue(); DriveApp.getFileById(documentId).setName("PwC's Academy_"+Name_of_client+"_"+Name_of_programme+"_"+Month); var FileName = Name_of_programme; //Get the document body as a variable var body = SlidesApp.openById(documentId); body.replaceAllText('{Name of programme}', Name_of_programme); var lastSlide = body.getSlides(); lastSlide[5].remove();

我希望继续使脚本包含选择多个幻灯片的功能.我看到了下面的脚本来复制一张幻灯片,但无法弄清楚如何轻松地复制多张幻灯片.

I am looking to continue the script to include a function to select multiple slides. I saw the below script to copy one slide but have not been able to figure out how to copy multiple slides easily.

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);

我想让人们选择要在Google表单中包括哪些幻灯片作为多项选择.

I want to give people the choice to select which slides to include on the google form as multiple choice.

在脚本的后端,我需要用幻灯片编号映射幻灯片的名称吗?还是可以在每张幻灯片的文本框中包含唯一的引用,然后选择相关的幻灯片?在这里大声思考.任何指导将不胜感激.

At the back end of the script, would I need to map the names of the slides with slide numbers? or can have include a unique reference in a text box on each slide and then select the relevant slide? Thinking out loud here. Any guidance would be appreciated.

推荐答案

  • 您要将主Google幻灯片中的5、7和9页(索引分别为4、6和8)复制到其他Google幻灯片.
  • 您想使用Google Apps脚本实现这一目标.
  • 我可以像上面那样理解.如果我的理解是正确的,那么这个答案呢?请认为这只是几个可能的答案之一.

    I could understand like above. If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

  • 从主Google幻灯片中检索所有幻灯片.
  • 在循环中将所需的幻灯片复制到目标Google幻灯片.
  • 模式1: 示例脚本:

    在运行脚本之前,请设置变量.

    Pattern 1: Sample script:

    Before you run the script, please set the variables.

    function myFunction() { var copyPageNumbers = [5, 7, 9]; // Please set the page number. This is not the index. So the 1st page is 1. var masterGoogleSlidesId = "###"; // Please set the master Google Slides ID. var destinationGoogleSlidesId = "###"; // Please set the destination Google Slides ID. var offset = 1; var src = SlidesApp.openById(masterGoogleSlidesId); var dst = SlidesApp.openById(destinationGoogleSlidesId); var slides = src.getSlides(); var page = 0; slides.forEach(function(slide, i) { if (copyPageNumbers.indexOf(i + 1) != -1) { dst.insertSlide(offset + page, slide); page++; } }); }

    模式2: 示例脚本:

    function myFunction() { var copyPageNumbers = [5, 7, 9]; // Please set the page number. This is not the index. So the 1st page is 1. var masterGoogleSlidesId = "###"; // Please set the master Google Slides ID. var destinationGoogleSlidesId = "###"; // Please set the destination Google Slides ID. var offset = 1; var src = SlidesApp.openById(masterGoogleSlidesId); var dst = SlidesApp.openById(destinationGoogleSlidesId); var slides = src.getSlides(); copyPageNumbers.forEach(function(p, i) { dst.insertSlide(offset + i, slides[p - 1]); }); }

    注意:

    • 在两种模式下,主Google幻灯片的5、7和9页均从目标Google幻灯片的第二页复制.
      • 使用var offset = 0时,将从目标Google幻灯片的第一页复制Google幻灯片母版的5、7和9页.
      • Note:

        • In both patterns, the pages of 5, 7 and 9 of the master Google Slides are copied from 2nd page in the destination Google Slides.
          • When var offset = 0 is used, the pages of 5, 7 and 9 of the master Google Slides are copied from 1st page in the destination Google Slides.
            • insertSlide(insertionIndex,slide)

更多推荐

使用Google Apps脚本从主幻灯片台复制多张幻灯片

本文发布于:2023-10-31 10:06:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:幻灯片   脚本   多张   Google   Apps

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!