简体   繁体   English

Google App脚本:广泛的执行时间

[英]Google App Script: wide range of execution time

I have a simple function to move the cursor to another place of the spreadsheet. 我有一个简单的功能,可以将光标移动到电子表格的另一个位置。 Sometime this code takes 30 seconds to execute, sometimes it takes 1 second to execute, which makes it useless. 有时此代码需要30秒才能执行,有时需要1秒才能执行,这使其变得无用。 Is there a way to recode it so the execution time is more consistent? 有没有一种方法可以对其重新编码,以使执行时间更加一致?

function go_to(){
var ss = SpreadsheetApp.getActiveSpreadsheet()
var active = SpreadsheetApp.getActiveRange().getValue()
var sheet = ss.getSheetByName("Records")
var range = sheet.getRange("B"+(active+2))
sheet.setActiveRange(range)
}

This seems pretty consistent in time performance for me. 对于我来说,这在时间表现上似乎相当一致。 How's it work on your setup? 在您的设置中如何运作?

    function go_to()
{
  var sht = SpreadsheetApp.getActiveSheet();
  var rsht = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Records');
  rsht.setActiveRange(rsht.getRange("B" + Number(sht.getActiveRange().getValue() + 2)));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM