我有一个可以使用全局变量轻松解决的问题,但是据我所知,我不知道如何面对它们,因为我的目标是使用按钮暂停onEdit(event)函数,以便一分钟,我可以编辑我的工作表而不会造成混乱。
由于某些原因,当我不得不编辑工作表时,我使用函数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
}
}
如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
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句