我尝试设置Google Apps脚本,以便每周自动将Google幻灯片文档的副本保存到云端硬盘文件夹中。我意识到幻灯片总是备份,但我想保存一份不断发展的文档的每周副本以供参考。
这是我尝试运行的脚本:
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);
}
我出错的任何想法?
答案 0 :(得分:0)
您使用的是用于Google文档的DocumentApp
,而不是幻灯片。相反,它应该是SlidesApp.getActivePresentation()
。
如果您希望使用.getId()和.getFileById()后跟{.getParents(),请使用DriveApp
来获取当前文件夹,而不是对文件夹ID进行硬编码。 {3}}。虽然如果要将副本保存在单独的文件夹中,请忽略它。