Class DataValidation

DataValidation

Dostęp do reguł sprawdzania poprawności danych. Aby utworzyć nową regułę, użyj elementów SpreadsheetApp.newDataValidation() i DataValidationBuilder. Za pomocą Range.setDataValidation(rule), aby ustawić regułę weryfikacji dla zakresu.

// Log information about the data validation rule for cell A1.
var cell = SpreadsheetApp.getActive().getRange('A1');
var rule = cell.getDataValidation();
if (rule != null) {
  var criteria = rule.getCriteriaType();
  var args = rule.getCriteriaValues();
  Logger.log('The data validation rule is %s %s', criteria, args);
} else {
  Logger.log('The cell does not have a data validation rule.')
}

Metody

MetodaZwracany typKrótki opis
copy()DataValidationBuilderTworzy kreator reguły sprawdzania poprawności danych na podstawie jej ustawień.
getAllowInvalid()BooleanZwraca true, jeśli reguła wyświetla ostrzeżenie, gdy dane wejściowe nie przejdą weryfikacji, lub false, jeśli dane wejściowe są całkowicie odrzucone.
getCriteriaType()DataValidationCriteriaPobiera typ kryteriów reguły określony w wyliczenie DataValidationCriteria.
getCriteriaValues()Object[]Pobiera tablicę argumentów dla kryteriów reguły.
getHelpText()StringPobiera tekst pomocy dotyczący reguły lub null, jeśli nie został ustawiony żaden tekst pomocy.

Szczegółowa dokumentacja

copy()

Tworzy kreator reguły sprawdzania poprawności danych na podstawie jej ustawień.

// 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);

Powrót

DataValidationBuilder – kreator oparty na ustawieniach tej reguły


getAllowInvalid()

Zwraca true, jeśli reguła wyświetla ostrzeżenie, gdy dane wejściowe nie przejdą weryfikacji, lub false, jeśli dane wejściowe są całkowicie odrzucone. Wartość domyślna nowych reguł sprawdzania poprawności danych to true.

Powrót

Booleantrue, jeśli reguła zezwala na dane wejściowe, które nie przeszły weryfikacji danych; false, jeśli nie


getCriteriaType()

Pobiera typ kryteriów reguły określony w wyliczenie DataValidationCriteria. Aby uzyskać jako argumentów kryteriów użyj getCriteriaValues(). Aby użyć tych wartości do utworzenia lub zmienić regułę sprawdzania poprawności danych, patrz DataValidationBuilder.withCriteria(criteria, args).

// Log information about the data validation rule for cell A1.
var cell = SpreadsheetApp.getActive().getRange('A1');
var rule = cell.getDataValidation();
if (rule != null) {
  var criteria = rule.getCriteriaType();
  var args = rule.getCriteriaValues();
  Logger.log('The data validation rule is %s %s', criteria, args);
} else {
  Logger.log('The cell does not have a data validation rule.')
}

Powrót

DataValidationCriteria – typ kryteriów sprawdzania poprawności danych;


getCriteriaValues()

Pobiera tablicę argumentów dla kryteriów reguły. Aby uzyskać typ kryterium, użyj getCriteriaType(). Aby użyć tych wartości do utworzenia lub zmodyfikowania reguły sprawdzania poprawności danych, zobacz DataValidationBuilder.withCriteria(criteria, args).

// Log information about the data validation rule for cell A1.
var cell = SpreadsheetApp.getActive().getRange('A1');
var rule = cell.getDataValidation();
if (rule != null) {
  var criteria = rule.getCriteriaType();
  var args = rule.getCriteriaValues();
  Logger.log('The data validation rule is %s %s', criteria, args);
} else {
  Logger.log('The cell does not have a data validation rule.')
}

Powrót

Object[] – tablica argumentów odpowiednich do typu kryteriów reguły; liczba argumentów i ich typ pasują do odpowiedniej metody require...() klasy DataValidationBuilder


getHelpText()

Pobiera tekst pomocy dotyczący reguły lub null, jeśli nie został ustawiony żaden tekst pomocy.

Powrót

String – tekst pomocy reguły lub null, jeśli nie ustawiono tekstu pomocy;