Dostęp do reguł sprawdzania poprawności danych. Aby utworzyć nową regułę, użyj SpreadsheetApp.newDataValidation()
i DataValidationBuilder
. Możesz użyć funkcji 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
Metoda | Zwracany typ | Krótki opis |
---|---|---|
copy() | DataValidationBuilder | Tworzy konstruktor dla reguły sprawdzania poprawności danych na podstawie ustawień tej reguły. |
getAllowInvalid() | Boolean | Zwraca wartość true , jeśli reguła wyświetla ostrzeżenie, gdy dane wejściowe nie przejdą weryfikacji, lub false , jeśli dane wejściowe zostaną całkowicie odrzucone. |
getCriteriaType() | DataValidationCriteria | Pobiera typ kryterium reguły zgodnie z definicją w wyliczeniu DataValidationCriteria . |
getCriteriaValues() | Object[] | Pobiera tablicę argumentów dla kryteriów reguły. |
getHelpText() | String | Pobiera tekst pomocy dotyczący reguły lub null , jeśli nie ustawiono żadnego tekstu pomocy. |
Szczegółowa dokumentacja
copy()
Tworzy konstruktor dla reguły sprawdzania poprawności danych na podstawie ustawień tej reguły.
// 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);
Powroty
DataValidationBuilder
– kreator oparty na ustawieniach tej reguły,
getAllowInvalid()
Zwraca wartość true
, jeśli reguła wyświetla ostrzeżenie, gdy dane wejściowe nie przejdą weryfikacji, lub false
, jeśli dane wejściowe zostaną całkowicie odrzucone. Domyślnie nowe reguły sprawdzania poprawności danych to true
.
Powroty
Boolean
– true
, jeśli reguła zezwala na dane wejściowe, których weryfikacja się nie powiodła; jeśli nie, false
getCriteriaType()
Pobiera typ kryterium reguły zgodnie z definicją w wyliczeniu DataValidationCriteria
. Aby uzyskać argumenty kryteriów, użyj getCriteriaValues()
. Aby użyć tych wartości do utworzenia lub zmiany 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.') }
Powroty
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 zmiany 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.') }
Powroty
Object[]
– tablica argumentów odpowiednich do typu kryterium 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 ustawiono żadnego tekstu pomocy.
Powroty
String
– tekst pomocy dotyczący reguły lub null
, jeśli nie ustawiono tekstu pomocy.