我如何改变这个脚本应用下拉栏b &用C代替A &B ?(脚本似乎工作完美,如果下拉栏是在A &;b)
A列是日期,B列是下拉列表(从"作物"工作表)和列C将是一个从属的下拉列表(从"裁剪"表)。当我更改"一级列"时(第3行)和"第二层列";(第4行)等于2 (col B) &3 (col C)分别在脚本编辑器中输入日期,然后在工作表的a栏中输入日期,在B栏中输入下拉选项;C完全消失。
var MainWsName = "Harvest";
var CropsWsName = "Crops";
var firstLevelColumn = 2;
var secondLevelColumn = 3;
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(MainWsName);
var wsCrops = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(CropsWsName);
var Crops = wsCrops.getRange(2, 1,wsCrops.getLastRow()-1,3).getValues();
function onEdit(activeCell){
var activeCell = ws.getActiveCell();
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)
}//close If
}// 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 filteredCrops = Crops.filter(function(o){ return o[0] === val });
var listToApply = filteredCrops.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);
}
function onEdit(e) {
if (sh.getName() == 'Harvest' && e.range.columnStart > 1 && e.range.columnStart < 4 && e.range.rowStart > 1) {
applyFirstLevelValidation(e.value, e.range.rowStart)
}
}
你不能在触发器函数中使用参数。我不明白onEdit(e)