2
我想使用Google Apps腳本動態更改Google Spreadsheet單元格驗證功能中候選列表的值。我需要從其他電子表格中獲取值。在Google應用程序腳本中創建動態下拉列表
我想使用Google Apps腳本動態更改Google Spreadsheet單元格驗證功能中候選列表的值。我需要從其他電子表格中獲取值。在Google應用程序腳本中創建動態下拉列表
如果我正確地理解了你的話,這是我一直在努力的。通常我使用IMPORTRANGE爲「本地化」的遙控器列表但這還沒有在新的谷歌電子表格的工作...所以你可以嘗試像一個更直接的方法如下:
function setDropdown(){
var sourceSS = SpreadsheetApp.openById('yourSpreadsheetID'); // replace yourSpreadsheetID with the value in the sheet URL
var ss = SpreadsheetApp.getActive();
// get the range where the dynamic dropdown list is kept in the source spreadsheet
var dynamicList = sourceSS.getSheetByName('Dropdown List Sheet').getRange('A2:A'); // set to your sheet and range
// define the dropdown/validation rules
var rangeRule = SpreadsheetApp.newDataValidation().requireValueInRange(dynamicList).build();
// set the dropdown validation for the row
ss.getRange('sheet 1!A5:A10').setDataValidation(rangeRule); // set range to your range
}
我懷疑的是,上述不尚未在新的Google電子表格中工作。下面的修改將範圍轉換爲值列表。這是在一個短名單上測試,並做的工作...
function setDropdown(){
var sourceSS = SpreadsheetApp.openById('yourSpreadsheetID'); // replace yourSpreadsheetID with the value in the sheet URL
var ss = SpreadsheetApp.getActive();
// get the range where the dynamic dropdown list is kept in the source spreadsheet
var dynamicList = sourceSS.getSheetByName('Dropdown List Sheet').getRange('A2:A10'); // set to your sheet and range
var arrayValues = dynamicList.getValues();
// define the dropdown/validation rules
var rangeRule = SpreadsheetApp.newDataValidation().requireValueInList(arrayValues);
// set the dropdown validation for the row
ss.getRange('sheet 1!A5:A10').setDataValidation(rangeRule); // set range to your range
}
嘿,我試過解決方案,但不幸的是不工作。我正在使用新版Google電子表格。歡呼 –
請參閱新的Google Spreadsheet中的alternative ... possibleValueInRange()函數。使用價值清單似乎可以完成這項工作。 –
不錯。這項工作。謝謝 :) –