我有一个问题,我很容易用全局变量解决,但我不知道如何面对这里因为它们不存在,据我所知 我的目标是使用一个按钮暂停onEdit(事件)功能,这样我可以在一分钟内编辑我的工作表而不会造成混乱。
我使用函数onEdit(event)自动添加工作表中人员的入口和出口时间 当我由于某些原因编辑工作表时,但我没有在工作表中插入任何新人,onEdit会抓住每个编辑作为插入一个人,并且工作表变得一团糟。 我想知道如何通过一个名为“WAIT1MINUTE”的外部按钮调用脚本1分钟。
我可以这样创建按钮:
function onOpen(){
var ui=SpreadsheetApp.getUi();
ui.createMenu('Wait')
.addItem('Wait','WAIT1MINUTE')
.addToUi();}
我对全局变量的处理方法如下
global a=1; //automatic completion is ON
function WAIT1MINUTE{
a=0; //automatic completion is OFF
Utilities.sleep(60000);
a=1;//automatic completion is ON
}
function onEdit(event,a){
if(a) { //automatic completion is ON
// do the automatic completion of time entrance and exit
}
}
答案 0 :(得分:2)
正如Pierre的评论中所建议的那样,您希望使用PropertiesService。
function WAIT1MINUTE() {
PropertiesService.getDocumentProperties().setProperty('a', 0);
Utilities.sleep(60000);
PropertiesService.getDocumentProperties().setProperty('a', 1);
}
function onEdit(event){
var a = PropertiesService.getDocumentProperties().getProperty('a');
if(a) { //automatic completion is ON
// do the automatic completion of time entrance and exit
}
}