如何将幻灯片从一个演示文稿复制到另一个演示文稿? [英] How to copy a slide from one presentation to another?

查看:144
本文介绍了如何将幻灯片从一个演示文稿复制到另一个演示文稿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从源演示文稿中复制幻灯片,并将其附加到目标演示文稿的末尾.我已经在SO上搜索了解决方案,但它们使用的是Google Apps脚本.我正在寻找可以使用Google幻灯片或Google Drive REST API的解决方案.

I am trying to copy slides from a source presentation and append them to the end of the destination presentation. I have searched solutions on SO but they use the google apps script. I am looking for a solution that can use google slides or google drive REST API.

到目前为止,我一直在尝试获取源演示文稿幻灯片的每个元素,并使用批处理更新将它们添加到目标演示文稿中,但这显然很乏味,并且不能涵盖所有情况.

What I have attempted so far is getting each element of the source presentation's slides and using batch updates to add them to the destination presentation, but obviously this is tedious and does not cover all cases.

有人可以执行此任务吗?

Does anyone have any possible ways to perform this task?

推荐答案

不幸的是,在当前阶段,没有任何方法可以将幻灯片直接复制到其他Google幻灯片中(就像Sheets API的copyTo方法一样),然而.因此,为了将一张幻灯片复制到其他幻灯片上,我认为有两种解决方法.

Unfortunately, in the current stage, there are no methods for directly copying a slide (It's like the method of copyTo of Sheets API.) to other Google Slides, yet. So in order to copy a slide to other Slides, I think that there are 2 workarounds.

  1. 通过get方法获取幻灯片中的所有对象和格式后,创建新幻灯片并使用batchUpdate方法放置对象.
  2. 使用Google Apps脚本创建API,因为GAS的幻灯片服务具有直接复制幻灯片的方法.

我建议使用后者,因为我认为前者将是复杂的脚本.因此,我想为后一种解决方法提出一个示例脚本.

I recommend the latter, because I think that the former will be the complicated script. So I would like to propose a sample script for the latter workaround.

使用此脚本时,请执行以下流程.

When you use this script, please do the following flow.

  1. 登录到Google云端硬盘. https://drive.google.com/drive/my-drive
  2. 创建新的独立项目.
  1. Log in to Google Drive. https://drive.google.com/drive/my-drive
  2. Create new standalone project.
    • Please create new project at https://script.google.com/.
  1. 在脚本编辑器上,通过发布"->作为Web应用程序部署"打开一个对话框.
  2. 在将应用程序执行为:"中选择我".
  3. 为谁有权访问该应用程序:"选择所有人,甚至匿名".
  4. 单击部署"按钮作为新的项目版本".
  5. 自动打开需要授权"对话框.
  1. On the script editor, Open a dialog box by "Publish" -> "Deploy as web app".
  2. Select "Me" for "Execute the app as:".
  3. Select "Anyone, even anonymous" for "Who has access to the app:".
  4. Click "Deploy" button as new "Project version".
  5. Automatically open a dialog box of "Authorization required".
  1. 点击查看权限".
  2. 选择自己的帐户.
  3. 在此应用未验证"中单击高级".
  4. 点击转到###项目名称###(不安全)"
  5. 单击允许"按钮.

  • 复制当前的Web应用程序URL:".
    • 就像https://script.google.com/macros/s/#####/exec.
    • Copy "Current web app URL:".
      • It's like https://script.google.com/macros/s/#####/exec.
      • 通过此流程,将Web Apps部署为自己的API.在此示例中,谁有权访问该应用程序:"的所有人,甚至匿名"被用作测试.如果要使用访问令牌,请进行修改.您可以在下面的参考"中查看详细信息.

        By this flow, the Web Apps was deployed as own API. In this sample, "Anyone, even anonymous" for "Who has access to the app:" was used as a test. If you want to use the access token, please modify this. You can see the detail information at below "References".

        function doGet(e) {
          var srcId = e.parameters.srcId;
          var dstId = e.parameters.dstId;
          var srcPage = e.parameters.srcPage;
          var srcSlide = SlidesApp.openById(srcId);
          var dstSlide = SlidesApp.openById(dstId);
          var copySlide = srcSlide.getSlides()[srcPage - 1];
          dstSlide.appendSlide(copySlide);
          return ContentService.createTextOutput("Done.");
        }
        

        curl命令:

        在部署Web Apps之后,您可以将Web Apps用作自己的API.请求到已部署的Web Apps的示例curl如下.

        curl command:

        After Web Apps was deployed, you can use the Web Apps as own API. The sample curl for requesting to the deployed Web Apps is as follows.

        在使用此功能之前,请设置幻灯片的源文件ID和目标文件ID.当您要复制源幻灯片的第一页时,请将1设置为srcPage.并且还请设置上面检索到的端点.

        Before you use this, please set the source and destination file ID of Slides. When you want to copy the 1st page of the source Slides, please set 1 to srcPage. And also please set the endpoint which was retrieved above.

        curl -GL \
          -d "srcId=### fileId of source Slides ###" \
          -d "dstId=### fileId of destination Slides ###" \
          -d "srcPage=1" \
          "https://script.google.com/macros/s/#####/exec"
        

        运行此命令时,将返回Done..那时,您可以在目标幻灯片中看到附加到最后一页的幻灯片.

        When this command is run, Done. is returned. At that time, you can see the appended slide to the last page in the destination Slides.

        • Standalone Scripts
        • Web Apps
        • Taking advantage of Web Apps with Google Apps Script
        • openById()
        • getSlides()
        • appendSlide()

        这篇关于如何将幻灯片从一个演示文稿复制到另一个演示文稿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆