Created
June 9, 2014 13:41
-
-
Save nikushi/78d8b6a036bc1c18ce91 to your computer and use it in GitHub Desktop.
スプレッドシート間でデータバリデーションのリストを構築する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
var ss = SpreadsheetApp.getActive(); | |
var sh = ss.getSheetByName('sheet 1'); | |
var range = sh.getRange('A2:A'); | |
setValidation(range); | |
} | |
function setValidation(range) { | |
range.setDataValidation(dataValidator()); | |
} | |
function dataValidator() { | |
var ss = SpreadsheetApp.openById('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); // "data source" spreadsheet | |
var sh = ss.getSheetByName('source-sheet'); | |
// 他シートのrangeインスタンスを参照する方法を試したが | |
// requireValueInRange(range) で渡すとrange参照できずエラーに成ったので | |
// rangeからvalueをとり出しrequireValueInList(values)で代用した | |
var values = sh.getRange('A2:A').getValues().map(function(a) { return a[0] }); | |
Logger.log(values); | |
return SpreadsheetApp.newDataValidation().requireValueInList(values) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment