Dostęp do reguł sprawdzania poprawności danych. Aby utworzyć nową regułę, użyj SpreadsheetApp.newDataValidation() i DataValidationBuilder. Za pomocą Range.setDataValidation(rule) możesz ustawić regułę weryfikacji zakresu.
// Log information about the data validation rule for cell A1. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = cell.getDataValidation(); if (rule != null) { const criteria = rule.getCriteriaType(); const 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() | Data | Tworzy narzędzie do tworzenia reguły weryfikacji danych na podstawie ustawień tej reguły. |
get | Boolean | Zwraca true, jeśli reguła wyświetla ostrzeżenie, gdy dane wejściowe nie przejdą weryfikacji danych, lub false, jeśli odrzuca dane wejściowe. |
get | Data | Pobiera typ kryteriów reguły zdefiniowany w wyliczeniu Data. |
get | Object[] | Pobiera tablicę argumentów dla kryteriów reguły. |
get | String | Zwraca tekst pomocy reguły lub null, jeśli nie jest ustawiony żaden tekst pomocy. |
Szczegółowa dokumentacja
copy()
Tworzy narzędzie do tworzenia reguły weryfikacji danych na podstawie ustawień tej reguły.
// Change existing data validation rules that require a date in 2013 to require // a date in 2014. const oldDates = [new Date('1/1/2013'), new Date('12/31/2013')]; const newDates = [new Date('1/1/2014'), new Date('12/31/2014')]; const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()); const rules = range.getDataValidations(); for (let i = 0; i < rules.length; i++) { for (let j = 0; j < rules[i].length; j++) { const rule = rules[i][j]; if (rule != null) { const criteria = rule.getCriteriaType(); const 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 – narzędzie do tworzenia na podstawie ustawień tej reguły.
getAllowInvalid()
Zwraca true, jeśli reguła wyświetla ostrzeżenie, gdy dane wejściowe nie przejdą weryfikacji danych, lub false, jeśli odrzuca dane wejściowe. Domyślna wartość nowych reguł sprawdzania poprawności danych to true.
Powrót
Boolean – true, jeśli reguła zezwala na wprowadzanie danych, które nie przejdą weryfikacji; false, jeśli nie.
getCriteriaType()
Pobiera typ kryteriów reguły zdefiniowany w wyliczeniu DataValidationCriteria. Aby uzyskać argumenty kryteriów, użyj funkcji getCriteriaValues(). Aby użyć tych wartości do utworzenia lub zmodyfikowania reguły sprawdzania poprawności danych, zapoznaj się z tym artykułem: DataValidationBuilder.withCriteria(criteria, args).
// Log information about the data validation rule for cell A1. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = cell.getDataValidation(); if (rule != null) { const criteria = rule.getCriteriaType(); const 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, zapoznaj się z sekcją DataValidationBuilder.withCriteria(criteria, args).
// Log information about the data validation rule for cell A1. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = cell.getDataValidation(); if (rule != null) { const criteria = rule.getCriteriaType(); const 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 dla typu kryteriów reguły; liczba argumentów i ich typ są zgodne z odpowiednią metodą require...() klasy DataValidationBuilder.
getHelpText()
Zwraca tekst pomocy reguły lub null, jeśli nie jest ustawiony żaden tekst pomocy.
Powrót
String – tekst pomocy reguły lub null, jeśli nie ustawiono tekstu pomocy.