Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何将依赖下拉列表应用于两张图纸_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 如何将依赖下拉列表应用于两张图纸

Google apps script 如何将依赖下拉列表应用于两张图纸,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我想在第一季度和第二季度的工作表上都有一个下拉列表,但只有在第一季度才有可能。 如何为两张图纸创建下拉列表? 答案是似乎没有在电子表格上操作。 我不知道该怎么办 首先 函数onEdit(){ var tabLists=“Q1”; var tabValidation=“数据”; var ss=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var DATAS=SpreadsheetApp.getActiveSpreadsheet().

我想在第一季度和第二季度的工作表上都有一个下拉列表,但只有在第一季度才有可能。 如何为两张图纸创建下拉列表? 答案是似乎没有在电子表格上操作。 我不知道该怎么办

首先

函数onEdit(){
var tabLists=“Q1”;
var tabValidation=“数据”;
var ss=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var DATAS=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(表格列表);
var activeCell=ss.getActiveCell();
如果(activeCell.getColumn()==1&&activeCell.getRow()>1&&ss.getSheetName()==tabValidation){
activeCell.offset(0,1.clearContent().clearDataValidations();
var makes=datass.getRange(1,1,1,datass.getLastColumn()).getValues();
var makeIndex=makes[0].indexOf(activeCell.getValue())+1;
如果(makeIndex!=0){
var validationRange=datass.getRange(3,makeIndex,datass.getLastRow());
var validationRule=SpreadsheetApp.newDataValidation().requireRewageInRange(validationRange.build();
activeCell.offset(0,1).setDataValidation(validationRule);
}  
}
}
第二

函数onEdit(){
var tabLists=“Q2”;
var tabValidation=“数据”;
var ss=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var DATAS=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(表格列表);
var activeCell=ss.getActiveCell();
如果(activeCell.getColumn()==1&&activeCell.getRow()>1&&ss.getSheetName()==tabValidation){
activeCell.offset(0,1.clearContent().clearDataValidations();
var makes=datass.getRange(1,1,1,datass.getLastColumn()).getValues();
var makeIndex=makes[0].indexOf(activeCell.getValue())+1;
如果(makeIndex!=0){
var validationRange=datass.getRange(3,makeIndex,datass.getLastRow());
var validationRule=SpreadsheetApp.newDataValidation().requireRewageInRange(validationRange.build();
activeCell.offset(0,1).setDataValidation(validationRule);
}  
}

当Google应用程序脚本项目有两个同名函数声明时,其中一个函数将不起作用,因为函数名称应该是唯一的

一个快速而肮脏的解决方案可能是重命名当前的on-edit函数,然后从
onEdit
函数调用它们,或者为每个函数创建一个可安装的触发器

更好的解决方案是重写函数的逻辑,将它们集成到一个函数中,特别是如果您将使用简单触发器并向其添加更多操作,因为简单触发器的最大执行时间较短(30秒)

相关的

function onEdit(e) {
  const sh=e.range.getSheet();
  //Logger.log(JSON.stringify(e));//add this if you want to learn more about event object.
  const sheets=['Q1','Q2'];//Enter names of sheets that you want script to work on
  if(sheets.indexOf(sh.getName())>-1 && e.range.columnStart==1 && e.range.rowStart>1) {
    //run your code in here and it will only work for sheets whose names are in sheets

  }
}