简体   繁体   English

Google Sheet Apps 脚本超出最长时间

[英]Google Sheet Apps Script Exceeding maximum time

I have a dynamic dropdown apps script running on only 1 cell and there are some other formulas running in my sheet.我有一个仅在 1 个单元格上运行的动态下拉应用程序脚本,并且我的工作表中还运行了一些其他公式。 Until 2 days before i could run the script onEdit but i cant seem to do so now.直到 2 天前我可以在编辑上运行脚本,但我现在似乎不能这样做。 When checked inside apps script execution page it shows "Exceeded maximum execution time".在应用程序脚本执行页面中检查时,它显示“超出最大执行时间”。 What can i do to resolve this?我能做些什么来解决这个问题?


var mainWsName = "Print Sheet";
var mainDataName = "Orders";
var FirstLevelColumn = 1;
var SecondLevelColumn = 2;
var ThirdLevelColumn = 3;
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(mainWsName);
var wsJO = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(mainDataName);
var JO = wsJO.getRange(2,1,wsJO.getLastRow()-1,2).getValues();


function onEdit(e){
  var activeCell = e.range;
  var val = activeCell.getValue();
  var r = activeCell.getRow();
  var c = activeCell.getColumn();
  var wsName = activeCell.getSheet().getName();
  if(wsName === mainWsName && c === FirstLevelColumn && r > 1){
     applyFirstLevelValidation(val,r); 
  }else if(wsName === mainWsName && c=== SecondLevelColumn && r > 1){
    applysecondLevelValidation(val,r);
  }
} //end onEdit

function applyFirstLevelValidation(val,r){ 

   if(val === ""){
    ws.getRange(r,SecondLevelColumn).clearContent();
    ws.getRange(r,SecondLevelColumn).clearDataValidations();
    } else {
      ws.getRange(r,SecondLevelColumn).clearContent();
      var filteredJO = JO.filter(function(o){return o[0] === val });
      var listToApply = filteredJO.map(function(o){return o[1]});
      var cell = ws.getRange(r,SecondLevelColumn);
      applyValidationToCell(listToApply,cell);
    }
}


function applyValidationToCell(list,cell){
  
             
  var rule=SpreadsheetApp.newDataValidation().requireValueInList(list).setAllowInvalid(false).build();        
  
   cell.setDataValidation(rule);

}

Tried executing app script to get dynamic dropdown based on my selection.尝试执行应用程序脚本以根据我的选择获取动态下拉列表。

The code you quote is suboptimal, but chances are that the bad performance you mention is caused by the spreadsheet rather than the script.您引用的代码不是最理想的,但您提到的性能不佳很可能是由电子表格而不是脚本引起的。 To improve spreadsheet performance, see these optimization tips .要提高电子表格性能,请参阅这些优化技巧

You may also want to take a look at the dependentDropDownLists_ script.您可能还想查看dependentDropDownLists_脚本。

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

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