Enum DataValidationCriteria

DataValidationCriteria

An enumeration representing the data-validation criteria that can be set on a range.


 // Change existing data-validation rules that require a date in 2013 to require a date in 2014.
 var oldDates = [new Date('1/1/2013'), new Date('12/31/2013')];
 var newDates = [new Date('1/1/2014'), new Date('12/31/2014')];
 var sheet = SpreadsheetApp.getActiveSheet();
 var range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());
 var rules = range.getDataValidations();

 for (var i = 0; i < rules.length; i++) {
   for (var j = 0; j < rules[i].length; j++) {
     var rule = rules[i][j];

     if (rule != null) {
       var criteria = rule.getCriteriaType();
       var args = rule.getCriteriaValues();

       if (criteria == SpreadsheetApp.DataValidationCriteria.DATE_BETWEEN
           && args[0].getTime() == oldDates[0].getTime()
           && args[1].getTime() == oldDates[1].getTime()) {
         // Create a builder from the existing rule, then change the dates.
         rules[i][j] = rule.copy().withCriteria(criteria, newDates).build();
       }
     }
   }
 }
 range.setDataValidations(rules);
 

Properties

PropertyTypeDescription
DATE_AFTEREnumRequires a date that is after the given value.
DATE_BEFOREEnumRequires a date that is before the given value.
DATE_BETWEENEnumRequires a date that is between the given values.
DATE_EQUAL_TOEnumRequires a date that is equal to the given value.
DATE_IS_VALID_DATEEnumRequires a date.
DATE_NOT_BETWEENEnumRequires a date that is not between the given values.
DATE_ON_OR_AFTEREnumRequire a date that is on or after the given value.
DATE_ON_OR_BEFOREEnumRequires a date that is on or before the given value.
NUMBER_BETWEENEnumRequires a number that is between the given values.
NUMBER_EQUAL_TOEnumRequires a number that is equal to the given value.
NUMBER_GREATER_THANEnumRequire a number that is greater than the given value.
NUMBER_GREATER_THAN_OR_EQUAL_TOEnumRequires a number that is greater than or equal to the given value.
NUMBER_LESS_THANEnumRequires a number that is less than the given value.
NUMBER_LESS_THAN_OR_EQUAL_TOEnumRequires a number that is less than or equal to the given value.
NUMBER_NOT_BETWEENEnumRequires a number that is not between the given values.
NUMBER_NOT_EQUAL_TOEnumRequires a number that is not equal to the given value.
TEXT_CONTAINSEnumRequires that the input contains the given value.
TEXT_DOES_NOT_CONTAINEnumRequires that the input does not contain the given value.
TEXT_EQUAL_TOEnumRequires that the input is equal to the given value.
TEXT_IS_VALID_EMAILEnumRequires that the input is in the form of an email address.
TEXT_IS_VALID_URLEnumRequires that the input is in the form of a URL.
VALUE_IN_LISTEnumRequires that the input is equal to one of the given values.
VALUE_IN_RANGEEnumRequires that the input is equal to a value in the given range.
CUSTOM_FORMULAEnumRequires that the input makes the given formula evaluate to true.

发送以下问题的反馈:

此网页
Apps Script
Apps Script