使用IF语句触发onOpen



我有一个脚本,当只打开某些工作表,而不打开与脚本绑定的电子表格中的其他工作表时,我想在open上运行该脚本。所需要的纸张都具有名称";代理报告-"NameOfAgent";。每个代理报告内部也有某些单元格,可用于IF条件语句。从逻辑上讲,我想要这个:

如果活性片的名称包含";代理人报告"->运行脚本ELSE什么都不做

或者,在活性片单元A2中;角色&quot->运行脚本ELSE什么都不做

谢谢你的帮助。

onOpen将在所有者或编辑器打开电子表格时执行,无论url参数中引用了什么工作表,但您可以在i上包含if语句,以控制满足条件时执行的操作。

/**
* This will be executed always that the owner or an editor opens the spreadsheet
*
*/
function onOpen(e){
if(SpreadsheetApp.getActiveSheet().getName() === 'Agent report'){
// This will be executen when the condition is true
doSomething();
} else {
// This will be executen when the condition is false
return; // This is actually not necessary as there isn't any statement after it.
}
}
/**
* Function to be called when the condition is met
*
*/
function doSomething(){
// do something
}

相关

  • 谷歌应用程序脚本:动态创建电子表格菜单项

最新更新