【问题标题】:Google Apps script to automate copies of Google Slides document用于自动复制 Google 幻灯片文档的 Google Apps 脚本
【发布时间】:2018-01-04 02:55:30
【问题描述】:

我正在尝试设置一个 Google Apps 脚本,以便每周自动将 Google 幻灯片文档的副本保存到云端硬盘文件夹中。我知道 Slides 总是会备份,但我想每周保存一份不断发展的文档以供参考。

这是我要运行的脚本:

function makeCopy() {

  var timeZone = Session.getScriptTimeZone();

// generates the timestamp and stores in variable formattedDate as
// year-month-date hour-minute-second
  var formattedDate = Utilities.formatDate(new Date(), timeZone , "yyyy-MM-dd' 'HH:mm:ss");

// gets the name of the original file and appends the word "copy"
// followed by the timestamp stored in formattedDate
  var name = DocumentApp.getActiveDocument().getName() + " Copy " + formattedDate;

// gets the destination folder by their ID. REPLACE
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx with your folder's ID
// that you can get by opening the folder in Google Drive
// and checking the URL in the browser's address bar
  var destination = DriveApp.getFolderById("MyFolderID");

// gets the current Google Sheet file
  var file = DriveApp.getFileById(DocumentApp.getActiveDocument().getId())

// makes copy of "file" with "name" at the "destination"
  file.makeCopy(name, destination);
}

任何想法我哪里出错了?

【问题讨论】:

    标签: google-apps-script google-slides


    【解决方案1】:

    您使用DocumentApp 用于 Google 文档,而不是幻灯片。相反,它应该是SlidesApp.getActivePresentation()。

    您也可以使用DriveApp 来获取当前文件夹,而不是硬编码文件夹 ID,如果您想通过使用.getId() 和.getFileById() 后跟.getParents() 将它们保持在一起。尽管如果您想将副本保存在单独的文件夹中,请忽略这一点。

    【讨论】:

      猜你喜欢
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 2020-03-19
      • 1970-01-01
      相关资源
      最近更新 更多