Otwieranie reguł sprawdzania poprawności danych. Aby utworzyć nową regułę, użyj elementów Spreadsheet i Data. Aby ustawić regułę walidacji dla zakresu, możesz użyć opcji Range.setDataValidation(rule).
// 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 kreator reguły walidacji danych na podstawie jej ustawień. |
get | Boolean | Zwraca wartość true, jeśli reguła wyświetla ostrzeżenie, gdy dane nie przejdą weryfikacji, lub wartość false, jeśli dane zostaną całkowicie odrzucone. |
get | Data | Pobiera typ kryteriów reguły z typu wyliczenia Data. |
get | Object[] | Pobiera tablicę argumentów dla kryteriów reguły. |
get | String | Pobiera tekst pomocy do reguły lub null, jeśli nie ma ustawionego tekstu pomocy. |
Szczegółowa dokumentacja
copy()
Tworzy kreator reguły walidacji danych na podstawie jej ustawień.
// 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
Data – kreator na podstawie ustawień tej reguły.
get Allow Invalid()
Zwraca wartość true, jeśli reguła wyświetla ostrzeżenie, gdy dane nie przejdą weryfikacji, lub wartość false, jeśli dane zostaną całkowicie odrzucone. Domyślna wartość dla nowych reguł sprawdzania poprawności danych to true.
Powrót
Boolean – true, jeśli reguła zezwala na dane, które nie spełniają kryteriów sprawdzania poprawności; false, jeśli nie zezwala.
get Criteria Type()
Pobiera typ kryteriów reguły z typu wyliczenia Data. Aby uzyskać argumenty dla kryteriów, użyj get. Aby użyć tych wartości do utworzenia lub zmodyfikowania reguły sprawdzania poprawności danych, zapoznaj się z artykułem Data.
// 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
Data – typ kryteriów sprawdzania poprawności danych
get Criteria Values()
Pobiera tablicę argumentów dla kryteriów reguły. Aby uzyskać typ kryteriów, użyj właściwości get. Aby użyć tych wartości do utworzenia lub zmodyfikowania reguły sprawdzania poprawności danych, zapoznaj się z artykułem Data.
// 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 do typu kryteriów reguły; liczba argumentów i ich typ odpowiadają odpowiadającej metodzie require...() klasy Data.
get Help Text()
Pobiera tekst pomocy do reguły lub null, jeśli nie ma ustawionego tekstu pomocy.
Powrót
String – tekst pomocy reguły lub null, jeśli nie ustawiono tekstu pomocy