Dostęp do reguł sprawdzania poprawności danych. Aby utworzyć nową regułę, użyj parametrów SpreadsheetApp.newDataValidation()
i DataValidationBuilder
. Możesz użyć 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 kreator walidacji 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 całkowicie odrzuci dane wejściowe. |
getCriteriaType() | DataValidationCriteria | Pobiera typ kryteriów reguły zgodnie z definicją w wyliczeniu DataValidationCriteria . |
getCriteriaValues() | Object[] | Pobiera tablicę argumentów dla kryteriów reguły. |
getHelpText() | String | Pobiera tekst pomocy reguły lub wartość null , jeśli nie ustawiono tekstu pomocy. |
Szczegółowa dokumentacja
copy()
Tworzy kreator walidacji 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);
Zwróć
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 całkowicie odrzuci dane wejściowe. Domyślnie nowe reguły sprawdzania poprawności danych to true
.
Zwróć
Boolean
– true
, jeśli reguła zezwala na wprowadzanie danych, które nie przechodzi weryfikacji danych; false
– jeśli nie
getCriteriaType()
Pobiera typ kryteriów reguły zgodnie z definicją w wyliczeniu DataValidationCriteria
. Aby uzyskać argumenty kryteriów, użyj funkcji getCriteriaValues()
. Jeśli chcesz użyć tych wartości do utworzenia lub zmodyfikowania reguły weryfikacji danych, zapoznaj się z artykułem 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.') }
Zwróć
DataValidationCriteria
– typ kryteriów weryfikacji danych.
getCriteriaValues()
Pobiera tablicę argumentów dla kryteriów reguły. Aby uzyskać typ kryterium, użyj getCriteriaType()
. Jeśli chcesz użyć tych wartości do utworzenia lub zmiany reguły sprawdzania poprawności danych, przeczytaj artykuł 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.') }
Zwróć
Object[]
– tablica argumentów odpowiednich dla typu kryterium reguły; liczba argumentów i ich typ pasują do odpowiedniej metody require...()
klasy DataValidationBuilder
getHelpText()
Pobiera tekst pomocy reguły lub wartość null
, jeśli nie ustawiono tekstu pomocy.
Zwróć
String
– tekst pomocy reguły lub null
, jeśli nie został ustawiony tekst pomocy;