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
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,我不熟悉应用程序脚本。我的背景是大型机,所以类似Java语言的术语和概念对我来说有点陌生。这是我的情况。我有几个谷歌电子表格非常相似,但彼此有点不同。我想使用相同的独立应用程序脚本重置这些谷歌电子表格中的字段。我编写的脚本在绑定容器时工作正常,但当我将其放入MyDrive中的Google Apps脚本(project?)文件中,并尝试使用分配给函数名resetRounds的按钮从中执行它时,我会出现“脚本未找到”错误。我不想在每个电子表格中都有相同脚本的副本。我是否需要做一些特殊的事情来将项目文

我不熟悉应用程序脚本。我的背景是大型机,所以类似Java语言的术语和概念对我来说有点陌生。这是我的情况。我有几个谷歌电子表格非常相似,但彼此有点不同。我想使用相同的独立应用程序脚本重置这些谷歌电子表格中的字段。我编写的脚本在绑定容器时工作正常,但当我将其放入MyDrive中的Google Apps脚本(project?)文件中,并尝试使用分配给函数名resetRounds的按钮从中执行它时,我会出现“脚本未找到”错误。我不想在每个电子表格中都有相同脚本的副本。我是否需要做一些特殊的事情来将项目文件连接到电子表格?什么可能导致“未找到”情况?任何帮助或建议都将不胜感激

这是存在于Google Apps脚本项目文件中的脚本

function resetRounds() {


  var ss = SpreadsheetApp.getActive();
  var ssName = ss.getName();
  var shRounds = ss.getSheetByName("Rounds");
  var shLog = ss.getSheetByName('Print-Log').getName();
  var shDDList = ss.getSheetByName("DD-Lists"); 

  // Restore SVE team name from DD-Lists sheet 
  var source = shDDList.getRange("A3"); /* Team name should be in cell A3 */
  var destn  = shRounds.getRange("D3"); /* copy it to Team Name cell */
  source.copyTo(destn, {contentsOnly:true}); /* copy contents only, not the formatting */
 
  // Reset visitor team name and Captains to trigger cell conditional formatting */ 
  destn = shRounds.getRange("L3").activate().setValue('None');
  destn = shRounds.getRange("N4").activate().setValue('None');
  
  
  // Set the date to 1/1/2001 to trigger conditional formatting
  // Week number will show as blank (0) when special date 1/1/2001 is used
  source = shDDList.getRange("A51"); /* Special date should be in cell A51 */
  destn  = shRounds.getRange("Q3");  /* Only the first cell needs to be selected */ 
  source.copyTo(destn, {contentsOnly:true}); /* copy contents only, not the formatting */

  // Restore times from DD-Lists sheet 
  source = shDDList.getRange("A5"); /* Round 1 time should be in cell A5 */
  destn  = shRounds.getRange("C6"); /* copy it to Round 1 cell */
  source.copyTo(destn, {contentsOnly:true}); /* copy contents only, not the formatting */

  source = shDDList.getRange("A6"); /* Round 2 time should be in cell A6 */
  destn  = shRounds.getRange("L6"); /* copy it to Round 2 cell */
  source.copyTo(destn, {contentsOnly:true}); /* copy contents only, not the formatting */

 // Reset court numbers 
  ss.getRange("B8:B13").activate().setValue('Y');  /* Court number 1 */
  ss.getRange("B15:B20").activate().setValue('2'); /* Court number 2 */
  ss.getRange("B22:B27").activate().setValue('3'); /* Court number 3 */
  ss.getRange("B29:B34").activate().setValue('4'); /* Court number 4 */
  ss.getRange("B36:B41").activate().setValue('5'); /* Court number 5 */
  ss.getRange("B43:B48").activate().setValue('6'); /* Court number 6 */
  // Clear round 1 and round 2 player names 
  ss.getRange("C8:C48").activate().clear({contentsOnly: true, skipFilteredRows: true}); 
  ss.getRange("E8:E48").activate().clear({contentsOnly: true, skipFilteredRows: true}); 
  ss.getRange("L8:L48").activate().clear({contentsOnly: true, skipFilteredRows: true}); 
  ss.getRange("N8:N48").activate().clear({contentsOnly: true, skipFilteredRows: true}); 
  // Clear round 1 and round 2 scores
  ss.getRange("G8:H48").activate().clear({contentsOnly: true, skipFilteredRows: true}); 
  ss.getRange("P8:Q48").activate().clear({contentsOnly: true, skipFilteredRows: true}); 
  // Clear scorekeeper names
  ss.getRange("C56:E59").activate().clear({contentsOnly: true, skipFilteredRows: true}); 
  ss.getRange("C61:E62").activate().clear({contentsOnly: true, skipFilteredRows: true}); 
  /* Reset cursor to Visitor */
  ss.getRange('L3:N3').activate();


  }
拟议的解决办法 您希望使用按钮从中心位置在图纸子集上运行脚本。不幸的是,按钮方面可能会使事情变得更复杂(最后给出一些建议),但是如果按钮不是必需的,并且您愿意从脚本编辑器(或基于时间的触发器)运行它,那么下面的方法应该可以工作:

函数resetRounds(){
var ID=[“[SS ID 1]”、“[SS ID 2]”、“[SS ID 3]”;//在此处添加电子表格ID
//这个'forEach'循环将遍历每个id
id.forEach((id)=>{
var ss=SpreadsheetApp.openById(id);//您不是调用“getActive”,而是通过id打开
//脚本的这一部分是不变的
var ssName=ss.getName();
var shRounds=ss.getSheetByName(“轮”);
var shLog=ss.getSheetByName(“打印日志”).getName();
var shDDList=ss.getSheetByName(“DD列表”);
//从DD列表表恢复SVE团队名称
var source=shDDList.getRange(“A3”);/*团队名称应位于单元格A3中*/
var destn=shRounds.getRange(“D3”);/*将其复制到团队名称单元格*/
source.copyTo(destn{
仅内容:是的,
});/*仅复制内容,不复制格式*/
//重置访客团队名称和队长以触发单元格条件格式设置*/
destn=shRounds.getRange(“L3”).activate().setValue(“无”);
destn=shRounds.getRange(“N4”).activate().setValue(“无”);
//将日期设置为2001年1月1日以触发条件格式设置
//使用特殊日期1/1/2001时,周数将显示为空白(0)
source=shDDList.getRange(“A51”);/*特殊日期应在单元格A51中*/
destn=shRounds.getRange(
“第三季度”
);/*只需选择第一个单元格*/
source.copyTo(destn{
仅内容:是的,
});/*仅复制内容,不复制格式*/
//从DD列表表恢复时间
source=shDDList.getRange(“A5”);/*第1轮时间应在单元格A5中*/
destn=shRounds.getRange(“C6”);/*将其复制到第1轮单元格*/
source.copyTo(destn{
仅内容:是的,
});/*仅复制内容,不复制格式*/
source=shDDList.getRange(“A6”);/*第二轮时间应在单元格A6中*/
destn=shRounds.getRange(“L6”);/*将其复制到第二轮单元格*/
source.copyTo(destn{
仅内容:是的,
});/*仅复制内容,不复制格式*/
//重置法庭号码
ss.getRange(“B8:B13”).activate().setValue(“Y”);/*1号球场*/
ss.getRange(“B15:B20”).activate().setValue(“2”);/*2号法庭*/
ss.getRange(“B22:B27”).activate().setValue(“3”);/*3号球场*/
ss.getRange(“B29:B34”).activate().setValue(“4”);/*4号球场*/
ss.getRange(“B36:B41”).activate().setValue(“5”);/*第5号法庭*/
ss.getRange(“B43:B48”).activate().setValue(“6”);/*第6号球场*/
//清除第一轮和第二轮玩家名称
ss.getRange(“C8:C48”)
.activate()
.clear({contentsOnly:true,skipFilteredRows:true});
ss.getRange(“E8:E48”)
.activate()
.clear({contentsOnly:true,skipFilteredRows:true});
ss.getRange(“L8:L48”)
.activate()
.clear({contentsOnly:true,skipFilteredRows:true});
ss.getRange(“N8:N48”)
.activate()
.clear({contentsOnly:true,skipFilteredRows:true});
//清除第1轮和第2轮分数
ss.getRange(“G8:H48”)
.activate()
.clear({contentsOnly:true,skipFilteredRows:true});
ss.getRange(“P8:Q48”)
.activate()
.clear({contentsOnly:true,skipFilteredRows:true});
//清楚记分员的名字
ss.getRange(“C56:E59”)
.activate()
.clear({contentsOnly:true,skipFilteredRows:true});
ss.getRange(“C61:E62”)
.activate()
.clear({contentsOnly:true,skipFilteredRows:true});
/*将光标重置为访问者*/
ss.getRange(“L3:N3”).activate();
//脚本的这一部分保持不变^^^^
});
}
这里所发生的一切是,它没有调用
getActive
来打开电子表格,而是调用
openById
。它从脚本顶部初始化的ID数组或列表中获取ID。然后对该数组调用
forEach
方法,该数组将对该列表中的每个项重复特定操作。我们使用每个项调用
openById
。这将为每个电子表格运行脚本,只要您有编辑权限

将其分配给按钮 您可以像以前一样拥有一个带有绑定脚本的工作表,但该工作表的所有功能都是有一个按钮。它本身没有任何数据,用户只需启动脚本,而无需进入脚本编辑器并手动运行

用扳机启动它 例如,您还可以查看每天自动运行此“主”脚本的触发器(链接如下)。如果失败,它还会给你发电子邮件

工具书类