Validation

Updated at:

This topic describes the API operations that are related to the Validation object of table documents.

Validation

Range.Validation

Queries the data validation rules for a specified range.

  • Syntax

    expression.Range.Validation

    expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Query a range object.
      const range = await app.Range('A1');
    
      // Query the data validation rules.
      const validation = await range.Validation;
    }

Methods

Range.Validation.Add()

Adds a data validation rule by using the Add() method.

  • Syntax

    expression.Range.Validation.Add({ Type, Operator, Formula1, Formula2 })

    expression: the document type application object.

  • Parameters

    Property

    Data type

    Required

    Description

    Type

    Enum

    Yes

    The data validation type. For more information, see XlDVType.

    Operator

    Enum

    No

    The data validation operator. For more information, see XlFormatConditionOperator.

    Formula1

    String

    No

    The first part of the data validation equation. The value cannot not exceed 255 characters in length.

    Formula2

    String

    No

    • The second part of the data validation equation when the value of the Operator parameter is xlBetween or xlNotBetween. The value cannot not exceed 255 characters in length.

    • Ignore this parameter if the value of the Operator parameter is not xlBetween or xlNotBetween .

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Query a range object.
      const range = await app.Range('A1');
    
      // Query the data validation rules.
      const validation = await range.Validation;
    
      // Add a data validation rule.
      await validation.Add({
        Type: app.Enum.XlDVType.xlValidateWholeNumber,
        Operator: app.Enum.XlFormatConditionOperator.xlBetween,
        Formula1: '1',
        Formula2: '5',
      });
    }

Range.Validation.Delete()

Deletes a data validation rule by using the Delete() method.

  • Syntax

    expression.Range.Validation.Delete()

    expression: the document type application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Query a range object.
      const range = await app.Range('A1');
    
      // Query the data validation rules.
      const validation = await range.Validation;
    
      // Add a data validation rule.
      await validation.Add({
        Type: app.Enum.XlDVType.xlValidateWholeNumber,
        Operator: app.Enum.XlFormatConditionOperator.xlBetween,
        Formula1: '1',
        Formula2: '5',
      });
    
      // Delete the data validation rule after 10,000 ms.
      setTimeout(async () => {
        await validation.Delete();
      }, 10000);
    }

Range.Validation.Modify()

Modifies a data validation rule by using the Modify() method.

  • Syntax

    expression.Range.Validation.Modify({ Type, Operator, Formula1, Formula2 })

    expression: the document type application object.

  • Parameters

    Property

    Data type

    Required

    Description

    Type

    Enum

    Yes

    The data validation type. For more information, see XlDVType.

    Operator

    Enum

    No

    The data validation operator. For more information, see XlFormatConditionOperator.

    Formula1

    String

    No

    The first part of the data validation equation. The value cannot not exceed 255 characters in length.

    Formula2

    String

    No

    • The second part of the data validation equation when the value of the Operator parameter is xlBetween or xlNotBetween. The value cannot not exceed 255 characters in length.

    • Ignore this parameter if the value of the Operator parameter is not xlBetween or xlNotBetween .

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Query a range object.
      const range = await app.Range('A1');
    
      // Query the data validation rules.
      const validation = await range.Validation;
    
      // Add a data validation rule.
      await validation.Add({
        Type: app.Enum.XlDVType.xlValidateWholeNumber,
        Operator: app.Enum.XlFormatConditionOperator.xlBetween,
        Formula1: '1',
        Formula2: '5',
      });
    
      // Modify the data validation rule after 10,000 ms.
      setTimeout(async () => {
        await validation.Modify({
          Type: app.Enum.XlDVType.xlValidateWholeNumber,
          Operator: app.Enum.XlFormatConditionOperator.xlNotBetween,
          Formula1: '1',
          Formula2: '5',
        });
      }, 10000);
    }