データ検証ルールのビルダー。
// Set the data validation for cell A1 to require a value from B1:B10. const cell = SpreadsheetApp.getActive().getRange('A1'); const range = SpreadsheetApp.getActive().getRange('B1:B10'); const rule = SpreadsheetApp.newDataValidation().requireValueInRange(range).build(); cell.setDataValidation(rule);
メソッド
詳細なドキュメント
build()
copy()
このルールの設定に基づいて、データ入力規則のビルダーを作成します。
// 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()
DataValidationCriteria 列挙型で定義されているルールの条件タイプを取得します。条件の引数を取得するには、getCriteriaValues() を使用します。これらの値を使用してデータ検証ルールを作成または変更するには、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() を使用します。これらの値を使用してデータ入力規則を作成または変更するには、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[] - ルールの条件タイプに適した引数の配列。引数の数とその型は、DataValidationBuilder クラスの対応する require...() メソッドと一致します。
getHelpText()
ルールのヘルプテキストを取得します。ヘルプテキストが設定されていない場合は null を取得します。
戻る
String - ルールのヘルプテキスト。ヘルプテキストが設定されていない場合は null
requireCheckbox()
入力がブール値であることを要求するデータ入力規則を設定します。この値はチェックボックスとしてレンダリングされます。
// Set the data validation for cell A1 to require a boolean value; the value is // rendered as a checkbox. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireCheckbox().build(); cell.setDataValidation(rule);
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireCheckbox(checkedValue)
入力が指定された値または空白であることを必須とするデータ検証ルールを設定します。入力が指定された値と一致すると、セルはオンのチェックボックスとしてレンダリングされます。入力が空白の場合、セルはオフのチェックボックスとしてレンダリングされます。
// Set the data validation for cell A1 to require a custom checked value that is // rendered as a checkbox. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireCheckbox('APPROVED').build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
checked | Object | チェックボックスがオンの場合に割り当てられる値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireCheckbox(checkedValue, uncheckedValue)
入力が指定された値のいずれかであることを要求するデータの入力規則を設定します。入力が checkedValue の場合、セルはチェックされたチェックボックスとしてレンダリングされます。入力が uncheckedValue の場合、セルはオフのチェックボックスとしてレンダリングされます。
// Set the data validation for cell A1 to require custom checked values that are // rendered as a checkbox. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireCheckbox('APPROVED', 'PENDING') .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
checked | Object | チェックボックスがオンの場合に割り当てられる値。 |
unchecked | Object | オフになっているチェックボックスに割り当てられた値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireDate()
日付を必須とするデータの入力規則を設定します。
// Set the data validation for cell A1 to require a date. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireDate().build(); cell.setDataValidation(rule);
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireDateAfter(date)
指定された値以降の日付を必須とするデータ検証ルールを設定します。Date オブジェクトの時刻フィールドは無視され、日、月、年のフィールドのみが使用されます。
// Set the data validation for cell A1 to require a date after January 1, 2013. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireDateAfter(new Date('1/1/2013')) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
date | Date | 受け入れられない最新の日付。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireDateBefore(date)
指定された値より前の日付を必須とするデータ入力規則を設定します。Date オブジェクトの時刻フィールドは無視され、日、月、年のフィールドのみが使用されます。
// Set the data validation for cell A1 to require a date before January 1, 2013. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireDateBefore(new Date('1/1/2013')) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
date | Date | 受け入れられない最も早い日付。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireDateBetween(start, end)
指定した 2 つの日付の間、またはどちらかの日付に該当する日付を必須とするデータの入力規則を設定します。Date オブジェクトの時刻フィールドは無視され、日、月、年のフィールドのみが使用されます。
// Set the data validation for cell A1 to require a date in 2013. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireDateBetween(new Date('1/1/2013'), new Date('12/31/2013')) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
start | Date | 受け入れ可能な最も早い日付。 |
end | Date | 許容される最新の日付。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireDateEqualTo(date)
指定された値と等しい日付を必須とするデータ検証ルールを設定します。Date オブジェクトの時刻フィールドは無視され、日、月、年のフィールドのみが使用されます。
// Set the data validation for cell A1 to require a date equal to January 1, // 2013. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireDateEqualTo(new Date('1/1/2013')) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
date | Date | 唯一の有効な日付。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireDateNotBetween(start, end)
指定した 2 つの日付の範囲外の日付を必要とするデータ検証ルールを設定します。Date オブジェクトの時刻フィールドは無視され、日、月、年のフィールドのみが使用されます。
// Set the data validation for cell A1 to require a date not in 2013. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireDateNotBetween(new Date('1/1/2013'), new Date('12/31/2013')) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
start | Date | 受け入れられない最も早い日付。 |
end | Date | 受け入れられない最新の日付。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireDateOnOrAfter(date)
指定された値以降の日付を必須とするデータ入力規則を設定します。Date オブジェクトの時刻フィールドは無視され、日、月、年のフィールドのみが使用されます。
// Set the data validation for cell A1 to require a date on or after January 1, // 2013. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireDateOnOrAfter(new Date('1/1/2013')) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
date | Date | 受け入れ可能な最も早い日付。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireDateOnOrBefore(date)
指定された値以前の日付を必須とするデータ入力規則を設定します。Date オブジェクトの時刻フィールドは無視され、日、月、年のフィールドのみが使用されます。
// Set the data validation for cell A1 to require a date on or before January 1, // 2013. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireDateOnOrBefore(new Date('1/1/2013')) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
date | Date | 許容される最新の日付。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireFormulaSatisfied(formula)
指定された数式が true に評価されることを要求するデータ検証ルールを設定します。
// Set the data validation for cell A1 to equal B1 with a custom formula. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireFormulaSatisfied('=EQ(A1,B1)') .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
formula | String | 入力が有効な場合に true と評価されるカスタム数式。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireNumberBetween(start, end)
2 つの指定された数値の範囲内にある数値、またはそのいずれかの数値を必要とするように、データの入力規則を設定します。
// Set the data validation for cell A1 to require a number between 1 and 10. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireNumberBetween(1, 10).build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
start | Number | 許容できる最小値。 |
end | Number | 許容可能な最大値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireNumberEqualTo(number)
データ検証ルールを設定して、指定された値と等しい数値を必須にします。
// Set the data validation for cell A1 to require a number equal // to 3.1415926536. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireNumberEqualTo(Math.PI).build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
number | Number | 許容される唯一の値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireNumberGreaterThan(number)
指定された値より大きい数値を必須とするデータ入力規則を設定します。
// Set the data validation for cell A1 to require a number greater than 0. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireNumberGreaterThan(0).build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
number | Number | 許容できない最大値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireNumberGreaterThanOrEqualTo(number)
指定された値以上の数値を必要とするデータ検証ルールを設定します。
// Set the data validation for cell A1 to require a number greater than or equal // to 0. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireNumberGreaterThanOrEqualTo(0) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
number | Number | 許容できる最小値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireNumberLessThan(number)
データ検証ルールを設定して、指定された値より小さい数値を必須にします。
// Set the data validation for cell A1 to require a number less than 0. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireNumberLessThan(0).build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
number | Number | 許容できない最小値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireNumberLessThanOrEqualTo(number)
データ検証ルールを設定して、指定された値以下の数値を必須にします。
// Set the data validation for cell A1 to require a number less than or equal to // 0. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireNumberLessThanOrEqualTo(0) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
number | Number | 許容可能な最大値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireNumberNotBetween(start, end)
データ検証ルールを設定して、指定した 2 つの数値の範囲外の数値を必須にします。
// Set the data validation for cell A1 to require a number not between 1 and 10. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireNumberNotBetween(1, 10).build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
start | Number | 許容できない最小値。 |
end | Number | 許容できない最大値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireNumberNotEqualTo(number)
指定された値と等しくない数値を必要とするデータ検証ルールを設定します。
// Set the data validation for cell A1 to require a number not equal to 0. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireNumberNotEqualTo(0).build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
number | Number | 唯一の許容できない値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireTextContains(text)
入力に指定された値が含まれることを必須とするデータの入力規則を設定します。
// Set the data validation for cell A1 to require any value that includes // "Google". const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireTextContains('Google').build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
text | String | 入力に含める必要がある値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireTextDoesNotContain(text)
入力に指定された値が含まれないようにデータ入力規則を設定します。
// Set the data validation for cell A1 to require any value that does not // include "@". const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireTextDoesNotContain('@').build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
text | String | 入力に含めてはならない値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireTextEqualTo(text)
入力が指定された値と等しいことを要求するデータ検証ルールを設定します。
// Set the data validation for cell A1 to require "Yes". const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireTextEqualTo('Yes').build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
text | String | 許容される唯一の値。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireTextIsEmail()
入力がメールアドレスの形式であることを必須とするデータ入力規則を設定します。
// Set the data validation for cell A1 to require text in the form of an email // address. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireTextIsEmail().build(); cell.setDataValidation(rule);
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireTextIsUrl()
入力が URL の形式であることを必須とするデータ検証ルールを設定します。
// Set the data validation for cell A1 to require text in the form of a URL. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation().requireTextIsUrl().build(); cell.setDataValidation(rule);
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireValueInList(values)
入力が指定された値のいずれかに等しいことを要求するデータの入力規則を設定します。
// Set the data validation for cell A1 to require "Yes" or "No", with a dropdown // menu. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireValueInList(['Yes', 'No']) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
values | String[] | 許容可能な値の配列。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireValueInList(values, showDropdown)
入力が指定された値のいずれかに等しいことを要求するデータ検証ルールを設定します。プルダウン メニューを非表示にするオプションもあります。
// Set the data validation for cell A1 to require "Yes" or "No", with no // dropdown menu. const cell = SpreadsheetApp.getActive().getRange('A1'); const rule = SpreadsheetApp.newDataValidation() .requireValueInList(['Yes', 'No'], false) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
values | String[] | 許容可能な値の配列。 |
show | Boolean | スプレッドシートで値のプルダウン メニューを表示する場合は true、それ以外の場合は false。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireValueInRange(range)
入力が指定された範囲内の値と等しいことを要求するデータ入力規則を設定します。
// Set the data validation for cell A1 to require a value from B1:B10, with a // dropdown menu. const cell = SpreadsheetApp.getActive().getRange('A1'); const range = SpreadsheetApp.getActive().getRange('B1:B10'); const rule = SpreadsheetApp.newDataValidation().requireValueInRange(range).build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
range | Range | 許容可能な値を含む範囲。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
requireValueInRange(range, showDropdown)
入力が指定された範囲内の値と等しいことを必須とするデータ入力規則を設定します。プルダウン メニューを非表示にするオプションもあります。
// Set the data validation for cell A1 to require value from B1:B10, with no // dropdown menu. const cell = SpreadsheetApp.getActive().getRange('A1'); const range = SpreadsheetApp.getActive().getRange('B1:B10'); const rule = SpreadsheetApp.newDataValidation() .requireValueInRange(range, false) .build(); cell.setDataValidation(rule);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
range | Range | 許容可能な値を含む範囲。 |
show | Boolean | スプレッドシートで値のプルダウン メニューを表示する場合は true、それ以外の場合は false。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
setAllowInvalid(allowInvalidData)
入力がデータ検証に失敗した場合に警告を表示するか、入力を完全に拒否するかを設定します。新しいデータ検証ルールのデフォルトは true です。
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
allow | Boolean | ルールでデータ検証に失敗した入力を許可する場合は true、許可しない場合は false。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
setHelpText(helpText)
ユーザーがデータ検証が設定されているセルにカーソルを合わせたときに表示されるヘルプテキストを設定します。
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
help | String | 設定するヘルプテキスト。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー
withCriteria(criteria, args)
データ検証ルールを DataValidationCriteria 値で定義された条件に設定します。通常、既存のルールの criteria と arguments から取得されます。
// 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);
パラメータ
| 名前 | タイプ | 説明 |
|---|---|---|
criteria | Data | データ検証条件のタイプ。 |
args | Object[] | 条件タイプに適した引数の配列。引数の数とその型は、上記の対応する require...() メソッドと一致します。 |
戻る
DataValidationBuilder - チェーン用のこのビルダー