Reputation: 40271
I'd like to limit the possible values that can be selected in a Google Spreadsheet. This is easily doable via the UI, but I'd like to accomplish this in an Apps Script. When I put in the following:
var sheet = // get a sheet from somewhere
sheet.getRange(row, column, numRows, numColumns).setDataValidation(dataValidation);
The editor autocompletes the "setDataValidation" method. The pop-up help says it takes a "DataValidation" class. However, I am unable to find any documentation for this class or this method.
Does anyone happen to know if this is actually supported? And if so, how one might use it?
Thank you
Upvotes: 1
Views: 4963
Reputation: 4467
I think its a new Feature. You can get a DataValidation by doing:
var r = SpreadsheetApp.openById("...").getActiveRange();
var dv = r.getDataValidation();
In the popup for dv.
you can see the following function:
requireValuesInList(String[] values) : DataValidation
requireValuesInRange(Range rangeApi) : DataValidation
setHelpText(String helpText) : DataValidation
setShowDropDown(boolean showDropDown) : DataValidation
Then you need to set the validation back on the range:
r.setDataValidation(dv);
Upvotes: 4