【问题标题】:Make a pause in the Sheets script, sleep not working在表格脚本中暂停一下,睡眠不起作用
【发布时间】:2020-06-01 20:20:44
【问题描述】:

我有一个脚本,我希望它暂停大约 1 分钟,然后再继续。现在使用 sleep() 函数,我得到的只是脚本等到执行所有操作,而不是在继续之前暂停。这是我的脚本:

  SpreadsheetApp.openById("").getRange('B1').setValue(SpreadsheetApp.openById("").getRange('B1').getValue() + 1);

  Utilities.sleep(60000);
  var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("OVERVIEW");
  var sourceData = sourceSheet.getDataRange().getValues();
  var targetSS = SpreadsheetApp.openById("").getSheetByName("RAWDATADUPS");
  var targetRangeTop = targetSS.getLastRow();
  targetSS.getRange(targetRangeTop+1,1,sourceData.length,sourceData[0].length).setValues(sourceData);

  var sourceSheet20 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("OVERVIEW20MIN");
  var sourceData20 = sourceSheet20.getDataRange().getValues();
  var targetSS20 = SpreadsheetApp.openById("").getSheetByName("RAWDATA20DUP");
  var targetRangeTop20 = targetSS20.getLastRow();
  targetSS20.getRange(targetRangeTop20+1,1,sourceData20.length,sourceData20[0].length).setValues(sourceData20);````

【问题讨论】:

  • 我很能理解这个问题。等待和暂停有什么区别?

标签: google-sheets time copy sleep pause


【解决方案1】:

根据 sleep 命令的位置,您只是在初始化变量之前等待。你的短语 continue 让我觉得在更远的地方一定有一些循环。如果是这种情况,那么您可以将 sleep 命令放入循环中,每次迭代都会暂停 1 分钟。

【讨论】:

    猜你喜欢
    • 2018-02-20
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 2021-12-11
    • 2012-10-10
    • 2012-04-10
    • 1970-01-01
    • 2013-05-23
    相关资源
    最近更新 更多