גישה לכללים לאימות נתונים. כדי ליצור כלל חדש, משתמשים בפקודות SpreadsheetApp.newDataValidation() ו-DataValidationBuilder. אפשר להשתמש ב-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.'); }
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
copy() | Data | יוצרת builder לכלל אימות נתונים על סמך ההגדרות של הכלל הזה. |
get | Boolean | הפונקציה מחזירה true אם הכלל מציג אזהרה כשהקלט נכשל באימות הנתונים, או false אם היא דוחה את הקלט לחלוטין. |
get | Data | מחזירה את סוג הקריטריון של הכלל כפי שמוגדר ב-enum Data. |
get | Object[] | מחזירה מערך של ארגומנטים לקריטריונים של הכלל. |
get | String | מחזירה את טקסט העזרה של הכלל, או null אם לא הוגדר טקסט עזרה. |
תיעוד מפורט
copy()
יוצרת builder לכלל אימות נתונים על סמך ההגדרות של הכלל הזה.
// 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);
חזרה
DataValidationBuilder – כלי ליצירת כללים שמבוסס על ההגדרות של הכלל הזה
getAllowInvalid()
הפונקציה מחזירה true אם הכלל מציג אזהרה כשהקלט נכשל באימות הנתונים, או false אם היא דוחה את הקלט לחלוטין. ברירת המחדל לכללים חדשים לאימות נתונים היא true.
חזרה
Boolean — true אם הכלל מאפשר קלט שנכשל באימות הנתונים; false אם לא
getCriteriaType()
מחזירה את סוג הקריטריון של הכלל כפי שמוגדר ב-enum DataValidationCriteria. כדי לקבל את הארגומנטים של הקריטריונים, משתמשים בפונקציה getCriteriaValues(). כדי להשתמש בערכים האלה כדי ליצור או לשנות כלל לאימות נתונים, אפשר לעיין במאמר 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.'); }
חזרה
DataValidationCriteria — סוג הקריטריונים לאימות הנתונים
getCriteriaValues()
מחזירה מערך של ארגומנטים לקריטריונים של הכלל. כדי לקבל את סוג הקריטריון, משתמשים בפונקציה getCriteriaType(). כדי להשתמש בערכים האלה ליצירה או לשינוי של כלל לאימות נתונים, אפשר לעיין במאמר 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.'); }
חזרה
Object[] — מערך של ארגומנטים שמתאימים לסוג הקריטריון של הכלל. מספר הארגומנטים
והסוג שלהם תואמים לשיטת require...() המתאימה של המחלקה DataValidationBuilder
getHelpText()
מחזירה את טקסט העזרה של הכלל, או null אם לא הוגדר טקסט עזרה.
חזרה
String – טקסט העזרה של הכלל, או null אם לא מוגדר טקסט עזרה