Compartir a través de


ExcelScript.DataValidationErrorAlert interface

Representa las propiedades de alerta de error para la validación de datos.

Comentarios

Ejemplos

/**
 * 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);
}

Propiedades

message

Representa el mensaje de alerta de error.

showAlert

Especifica si se debe mostrar un cuadro de diálogo de alerta de error cuando un usuario escribe datos no válidos. El valor predeterminado es true.

style

El tipo de alerta de validación de datos, consulte ExcelScript.DataValidationAlertStyle para obtener más información.

title

Representa el título del cuadro de diálogo de alerta de error.

Detalles de las propiedades

message

Representa el mensaje de alerta de error.

message: string;

Valor de propiedad

string

showAlert

Especifica si se debe mostrar un cuadro de diálogo de alerta de error cuando un usuario escribe datos no válidos. El valor predeterminado es true.

showAlert: boolean;

Valor de propiedad

boolean

style

El tipo de alerta de validación de datos, consulte ExcelScript.DataValidationAlertStyle para obtener más información.

style: DataValidationAlertStyle;

Valor de propiedad

title

Representa el título del cuadro de diálogo de alerta de error.

title: string;

Valor de propiedad

string