有没有一种方法可以限制/限制一次Google表格列中有多少个单元格正在执行

时间:2020-02-21 08:34:26

标签: google-apps-script google-sheets

我什至不知道该如何写我的头衔。但是基本上在我的GSheets中,我有一列包含一个脚本,并且我想限制一次执行脚本的单元数量。为了限制执行速度-因为导入了100行数据,但脚本调用的路由无法处理大量负载,所以我最终遇到了一堆!ERRORS,必须手动重新提交该数据。我在脚本中添加了。

function myFunc(value)
{
 var serviceUrl = "myUrl" + value;
 var response;
  try
  {
    response = UrlFetchApp.fetch(serviceUrl);
  }
  catch(err)
  {
    Logger.log(err);
  }
  finally
  {
    Logger.log(response.getContentText());
    response = JSON.parse(response.getContentText());
    var arr = [];
    arr.push(response.myValues);
    return arr; 
  }


}

1 个答案:

答案 0 :(得分:0)

您似乎遇到了所请求站点的API配额限制。

我建议您停止将错误数据粘贴到工作表中。通过直接使用try-catch,但可以根据需要进行调整。

示例:

function myFunc(value) {
  var serviceUrl = "yourUrl" + value;
  var arr = [];
  var response;
  try {

    // Try something that might throw errors
    response = UrlFetchApp.fetch(serviceUrl);
    Logger.log(response.getContentText());
    response = JSON.parse(response.getContentText());
    arr.push(response.myValues);
  }
  catch(err)  {
    // Catch any errors gracefully and handle them
    Logger.log(err);
  }
  finally {
    // This will always run, so make sure it is something that will not 
    // put erroneus data in your sheet
    if (arr.length > 0){
      Logger.log("Response content is: " + response);
    }
  }
}
相关问题