データ入力規則のビルダー。
// Set the data validation for cell A1 to require a value from B1:B10. var cell = SpreadsheetApp.getActive().getRange('A1'); var range = SpreadsheetApp.getActive().getRange('B1:B10'); var rule = SpreadsheetApp.newDataValidation().requireValueInRange(range).build(); cell.setDataValidation(rule);
Methods
詳細なドキュメント
build()
copy()
このルールの設定に基づいて、データ入力規則のビルダーを作成します。
// 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);
リターン
DataValidationBuilder
- このルールの設定に基づくビルダー
getAllowInvalid()
ルールが入力データの検証に失敗した場合に警告を表示する場合は true
を返し、入力を完全に拒否する場合は false
を返します。新しいデータの入力規則のデフォルトは true
です。
リターン
Boolean
- ルールで許可される入力がデータの検証で不合格になる場合は true
、そうでない場合は false
。
getCriteriaType()
DataValidationCriteria
列挙型で定義されているルールの条件タイプを取得します。条件の引数を取得するには、getCriteriaValues()
を使用します。これらの値を使用してデータ入力規則を作成または変更する方法については、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.') }
リターン
DataValidationCriteria
- データの検証条件のタイプ
getCriteriaValues()
ルールの条件に対応する引数の配列を取得します。条件タイプを取得するには、getCriteriaType()
を使用します。これらの値を使用してデータ入力規則を作成または変更する方法については、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.') }
リターン
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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var rule = SpreadsheetApp.newDataValidation().requireCheckbox('APPROVED').build(); cell.setDataValidation(rule);
パラメータ
名前 | 型 | 説明 |
---|---|---|
checkedValue | 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var rule = SpreadsheetApp.newDataValidation().requireCheckbox('APPROVED', 'PENDING').build(); cell.setDataValidation(rule);
パラメータ
名前 | 型 | 説明 |
---|---|---|
checkedValue | Object | チェックボックスに割り当てられた値。 |
uncheckedValue | Object | オフになっているボックスに割り当てられた値。 |
リターン
DataValidationBuilder
- このビルダー(チェーン用)
requireDate()
日付を要求するようにデータ入力規則を設定します。
// Set the data validation for cell A1 to require a date. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var rule = SpreadsheetApp.newDataValidation().requireFormulaSatisfied('=EQ(A1,B1)').build(); cell.setDataValidation(rule);
パラメータ
名前 | 型 | 説明 |
---|---|---|
formula | String | 入力が有効な場合に true と評価されるカスタム数式。 |
リターン
DataValidationBuilder
- このビルダー(チェーン用)
requireNumberBetween(start, end)
指定された 2 つの数値の間またはいずれか 1 つの数値を要求するようにデータ入力規則を設定します。
// Set the data validation for cell A1 to require a number between 1 and 10. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var rule = SpreadsheetApp.newDataValidation().requireNumberEqualTo(3.1415926536).build(); cell.setDataValidation(rule);
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | Number | 唯一の許容値です。 |
リターン
DataValidationBuilder
- このビルダー(チェーン用)
requireNumberGreaterThan(number)
指定された値より大きい数値を要求するようにデータ入力規則を設定します。
// Set the data validation for cell A1 to require a number greater than 0. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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". var cell = SpreadsheetApp.getActive().getRange('A1'); var 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 "@". var cell = SpreadsheetApp.getActive().getRange('A1'); var rule = SpreadsheetApp.newDataValidation().requireTextDoesNotContain('@').build(); cell.setDataValidation(rule);
パラメータ
名前 | 型 | 説明 |
---|---|---|
text | String | 入力に含めてはならない値。 |
リターン
DataValidationBuilder
- このビルダー(チェーン用)
requireTextEqualTo(text)
入力が指定された値と等しいことを要求するデータ入力規則を設定します。
// Set the data validation for cell A1 to require "Yes". var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var rule = SpreadsheetApp.newDataValidation().requireValueInList(['Yes', 'No'], false).build(); cell.setDataValidation(rule);
パラメータ
名前 | 型 | 説明 |
---|---|---|
values | String[] | 許容される値の配列。 |
showDropdown | Boolean | スプレッドシートに値のプルダウン メニューを表示する場合は true 、表示しない場合は false 。 |
リターン
DataValidationBuilder
- このビルダー(チェーン用)
requireValueInRange(range)
入力が指定された範囲内の値と等しいことを要求するデータ入力規則を設定します。
// Set the data validation for cell A1 to require a value from B1:B10, with a dropdown menu. var cell = SpreadsheetApp.getActive().getRange('A1'); var range = SpreadsheetApp.getActive().getRange('B1:B10'); var 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. var cell = SpreadsheetApp.getActive().getRange('A1'); var range = SpreadsheetApp.getActive().getRange('B1:B10'); var rule = SpreadsheetApp.newDataValidation().requireValueInRange(range, false).build(); cell.setDataValidation(rule);
パラメータ
名前 | 型 | 説明 |
---|---|---|
range | Range | 許容値を含む範囲。 |
showDropdown | Boolean | スプレッドシートに値のプルダウン メニューを表示する場合は true 、表示しない場合は false 。 |
リターン
DataValidationBuilder
- このビルダー(チェーン用)
setAllowInvalid(allowInvalidData)
入力がデータ検証に失敗したときに警告を表示するか、入力を完全に拒否するかを設定します。新しいデータの入力規則のデフォルトは true
です。
パラメータ
名前 | 型 | 説明 |
---|---|---|
allowInvalidData | Boolean | データの検証で不合格になる入力をルールで許可する必要がある場合は true 、そうでない場合は false 。 |
リターン
DataValidationBuilder
- このビルダー(チェーン用)
setHelpText(helpText)
データ検証が設定されているセルにユーザーがカーソルを合わせたときに表示されるヘルプテキストを設定します。
パラメータ
名前 | 型 | 説明 |
---|---|---|
helpText | 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. 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);
パラメータ
名前 | 型 | 説明 |
---|---|---|
criteria | DataValidationCriteria | データ検証基準のタイプ。 |
args | Object[] | 条件のタイプに適した引数の配列。引数の数とその型は、上記の require...() メソッドと同じです。 |
リターン
DataValidationBuilder
- このビルダー(チェーン用)