ExcelScript.DataValidation interface

現在の範囲に適用されるデータ検証を表します。

メソッド

clear()

現在の範囲からデータの入力規則をクリアします。

getErrorAlert()

無効なデータが入力された場合のエラー警告。

getIgnoreBlanks()

空白セルに対してデータ検証を実行するかどうかを指定します。 既定値は です true

getInvalidCells()

無効なセル値を RangeAreas 持つ 1 つ以上の四角形の範囲を含むオブジェクトを返します。 すべてのセル値が有効な場合、このメソッドは を返します null

getPrompt()

ユーザーがセルを選択したときにプロンプトを表示します。

getRule()

さまざまな種類のデータ検証条件を含むデータ検証ルール。

getType()

データ検証の種類については、「」を参照してください ExcelScript.DataValidationType

getValid()

すべてのセルの値がデータの入力規則に従っているかどうかを表します。 trueすべてのセル値が有効な場合、またはfalseすべてのセル値が無効な場合は を返します。 範囲内に null 有効なセル値と無効なセル値の両方がある場合は を返します。

setErrorAlert(errorAlert)

無効なデータが入力された場合のエラー警告。

setIgnoreBlanks(ignoreBlanks)

空白セルに対してデータ検証を実行するかどうかを指定します。 既定値は です true

setPrompt(prompt)

ユーザーがセルを選択したときにプロンプトを表示します。

setRule(rule)

さまざまな種類のデータ検証条件を含むデータ検証ルール。

メソッドの詳細

clear()

現在の範囲からデータの入力規則をクリアします。

clear(): void;

戻り値

void

getErrorAlert()

無効なデータが入力された場合のエラー警告。

getErrorAlert(): DataValidationErrorAlert;

戻り値

getIgnoreBlanks()

空白セルに対してデータ検証を実行するかどうかを指定します。 既定値は です true

getIgnoreBlanks(): boolean;

戻り値

boolean

getInvalidCells()

無効なセル値を RangeAreas 持つ 1 つ以上の四角形の範囲を含むオブジェクトを返します。 すべてのセル値が有効な場合、このメソッドは を返します null

getInvalidCells(): RangeAreas;

戻り値

getPrompt()

ユーザーがセルを選択したときにプロンプトを表示します。

getPrompt(): DataValidationPrompt;

戻り値

getRule()

さまざまな種類のデータ検証条件を含むデータ検証ルール。

getRule(): DataValidationRule;

戻り値

getType()

データ検証の種類については、「」を参照してください ExcelScript.DataValidationType

getType(): DataValidationType;

戻り値

/**
 * This sample reads and logs the data validation type of the currently selected range.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the currently selected range.
  let range = workbook.getSelectedRange();

  // Get the type (`DataValidationType`) of data validation applied to the range.
  let validationType = range.getDataValidation().getType();

  /*
   * Log the data validation type.
   * If the range has a single value, it logs that type.
   * If the range doesn't have data validation applied, it logs "None".
   * If the range has multiple different types of data validation, it logs "Inconsistent" or "MixedCriteria".
   */
  console.log(validationType.toString());
}

getValid()

すべてのセルの値がデータの入力規則に従っているかどうかを表します。 trueすべてのセル値が有効な場合、またはfalseすべてのセル値が無効な場合は を返します。 範囲内に null 有効なセル値と無効なセル値の両方がある場合は を返します。

getValid(): boolean;

戻り値

boolean

setErrorAlert(errorAlert)

無効なデータが入力された場合のエラー警告。

setErrorAlert(errorAlert: DataValidationErrorAlert): void;

パラメーター

戻り値

void

setIgnoreBlanks(ignoreBlanks)

空白セルに対してデータ検証を実行するかどうかを指定します。 既定値は です true

setIgnoreBlanks(ignoreBlanks: boolean): void;

パラメーター

ignoreBlanks

boolean

戻り値

void

setPrompt(prompt)

ユーザーがセルを選択したときにプロンプトを表示します。

setPrompt(prompt: DataValidationPrompt): void;

パラメーター

戻り値

void

/**
 * This script creates a text prompt that's shown in C2:C8 when a user enters the cell.
 */
function main(workbook: ExcelScript.Workbook) {
    // Get the data validation object for C2:C8 in the current worksheet.
    let selectedSheet = workbook.getActiveWorksheet();
    let dataValidation = selectedSheet.getRange("C2:C8").getDataValidation();

    // Clear any previous validation to avoid conflicts.
    dataValidation.clear();

    // Create a prompt to remind users to only enter first names in this column.
    dataValidation.setPrompt({ 
        showPrompt: true, 
        title: "First names only", 
        message: "Only enter the first name of the employee, not the full name." 
    });
}    

setRule(rule)

さまざまな種類のデータ検証条件を含むデータ検証ルール。

setRule(rule: DataValidationRule): void;

パラメーター

戻り値

void

/**
 * This script creates a data validation rule for the range B1:B5.
 * All values in that range must be a positive number.
 * Attempts to enter other values are blocked and an error message appears.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the range B1:B5 in the active worksheet.
  const currentSheet = workbook.getActiveWorksheet();
  const positiveNumberOnlyCells = currentSheet.getRange("B1:B5");

  // Create a data validation rule to only allow positive numbers.
  const positiveNumberValidation: ExcelScript.BasicDataValidation = {
    formula1: "0",
    operator: ExcelScript.DataValidationOperator.greaterThan
  };
  const positiveNumberOnlyRule: ExcelScript.DataValidationRule = {
    wholeNumber: positiveNumberValidation
  };

  // Set the rule on the range.
  const rangeDataValidation = positiveNumberOnlyCells.getDataValidation();
  rangeDataValidation.setRule(positiveNumberOnlyRule);

  // Create an alert to appear when data other than positive numbers are entered.
  const positiveNumberOnlyAlert: ExcelScript.DataValidationErrorAlert = {
    message: "Positive numbers only",
    showAlert: true,
    style: ExcelScript.DataValidationAlertStyle.stop,
    title: "Invalid data"
  };
  rangeDataValidation.setErrorAlert(positiveNumberOnlyAlert);
}