軟體:Google Excel
版本:
原先自己都只用過很簡單的驗證方式產生下拉選單
但最近看到「多層次」下拉選單想練習看看
參考網頁教學後
https://goo.gl/PTSQ9f
還是有些步驟無法理解
大概是Step 5之後
請問指令碼要如何執行才能產生「多層次選單」的功效呢?
目前測試Excel:https://goo.gl/kG4NZU
麻煩大家指導 謝謝~
Ps.我抄錄下來的程式碼是否有錯誤(或需要改寫才行呢?)
https://goo.gl/MmYHvj
- - - - - - -
function setDataValid_(range,sourceRange){
var rule =
SpreadsheetApp.newDataValidation().requireValuelnRange(SourceRange,true).build();
range.setDataValidation(rule);
}
function onEdit(){
var aSheet = spreadsheetApp.getActiveSheet();
var aCell = aSheet.getActiveCell();
var aColumn = aCell.getColumn();
if (aColumn == 1 && aSheet.getName() == '範例檔') {
var range = aSheet.getRange(aCell.getRow(), aColumn + 1);
var sourceRange =
SpreadsheetApp.getActiveSpreadsheet().getRangeByName(aCell.getValue());
setDataValid_(range, sourceRange);
}
if (aColumn == 1 && aSheet.getName() == '範例檔') {
var range = aSheet.getRange(aCell.getRow(), aColumn + 1);
var sourceRange =
SpreadsheetApp.getActiveSpreadsheet().getRangeByName(aCell.getValue());
setDataValid_(range, sourceRange);
}
}
- - - - - - - - - -