Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何在新的电子表格中自动创建触发器?_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 如何在新的电子表格中自动创建触发器?

Google apps script 如何在新的电子表格中自动创建触发器?,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我想做的是: 使用Google Apps脚本创建新的电子表格 为新创建的电子表格创建触发器 这是我的密码: 函数createfile(){ var timezone=Session.getScriptTimeZone(); var tempStartDate=新日期(); tempStartDate.setDate(tempStartDate.getDate()+21); var startDate=Utilities.formatDate(tempStartDate,时区,'yymmd')

我想做的是:

  • 使用Google Apps脚本创建新的电子表格
  • 为新创建的电子表格创建触发器
这是我的密码:

函数createfile(){
var timezone=Session.getScriptTimeZone();
var tempStartDate=新日期();
tempStartDate.setDate(tempStartDate.getDate()+21);
var startDate=Utilities.formatDate(tempStartDate,时区,'yymmd');
var tempEndDate=新日期();
tempEndDate.setDate(tempEndDate.getDate()+26);
var endDate=Utilities.formatDate(tempEndDate,时区,'yymmd');
var ss=SpreadsheetApp.openById('123c3znd64gfuvgnpcltbr54s');
//制作模板文件的副本
var documentId=DriveApp.getFileById('123C3ZND64GFUVGNPCLTBR54S').makeCopy().getId();
//重命名复制的文件
var file=DriveApp.getFileById(documentId).setName('testaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaatate+'-'+endDate);
ScriptApp.newTrigger('星期一')
.基于时间的()
.每小时(6)
.create();
}
在工作表上无法执行此操作 触发器是有限的,不能将基于时间的触发器附加到电子表格。您可以将其他触发器附加到其他电子表格,例如
onEdit
,但不能附加时钟触发器

基于时间的触发器附加到脚本

此外,脚本只能为自己创建基于时间的触发器,而不能为另一个脚本创建基于时间的触发器

你可能认为你可以从另一个脚本中创建一个新的脚本,并且有一个API,应用程序脚本API。但是,API不允许您使用它创建触发器

因此,不幸的是,无法创建项目的副本,然后完全从另一个脚本向其添加触发器。始终会涉及一些手动操作。您可以复制它,但要初始化触发器,需要从副本中运行函数

工具书类

您是否有任何错误,或者是否可以提供一些日志?