Skip to Content
ClassesFDataValidation

Class: FDataValidation

Properties

PropertyType

rule

IDataValidationRule

Methods

copy()

copy(): FDataValidationBuilder

Creates a new instance of FDataValidationBuilder using the current rule object

Returns

FDataValidationBuilder

A new FDataValidationBuilder instance with the same rule configuration

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const builder = dataValidation.copy(); const newRule = builder.setAllowInvalid(true).build();

delete()

delete(): boolean

Delete the data validation rule from the worksheet

Returns

boolean

true if the rule is deleted successfully, false otherwise

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const isDeleted = dataValidation.delete();

getAllowInvalid()

getAllowInvalid(): boolean

Gets whether invalid data is allowed based on the error style value

Returns

boolean

true if invalid data is allowed, false otherwise

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const allowsInvalid = dataValidation.getAllowInvalid();

getApplied()

getApplied(): boolean

Gets whether the data validation rule is applied to the worksheet

Returns

boolean

true if the rule is applied, false otherwise

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const isApplied = dataValidation.getApplied();

getCriteriaType()

getCriteriaType(): any

Gets the data validation type of the rule

Returns

any

The data validation type

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const type = dataValidation.getCriteriaType();

getCriteriaValues()

getCriteriaValues(): [string, string, string]

Gets the values used for criteria evaluation

Returns

[string, string, string]

An array containing the operator, formula1, and formula2 values

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const [operator, formula1, formula2] = dataValidation.getCriteriaValues();

getHelpText()

getHelpText(): string

Gets the help text information, which is used to provide users with guidance and support

Returns

string

Returns the help text information. If there is no error message, it returns an undefined value

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const helpText = dataValidation.getHelpText();

getRanges()

getRanges(): FRange[]

Gets the ranges to which the data validation rule is applied

Returns

FRange[]

An array of FRange objects representing the ranges to which the data validation rule is applied

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const ranges = dataValidation.getRanges();

getSheetId()

getSheetId(): string

Gets the sheet ID of the worksheet

Returns

string

The sheet ID of the worksheet

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const sheetId = dataValidation.getSheetId();

getUnitId()

getUnitId(): string

Gets the unit ID of the worksheet

Returns

string

The unit ID of the worksheet

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const unitId = dataValidation.getUnitId();

setCriteria()

setCriteria( type, values, allowBlank?): FDataValidation

Set Criteria for the data validation rule

Parameters

ParameterTypeDescription
typeDataValidationTypeThe type of data validation criteria
values[DataValidationOperator, string, string]An array containing the operator, formula1, and formula2 values
allowBlank?booleanWhether to allow blank values

Returns

FDataValidation

The current instance for method chaining

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); dataValidation.setCriteria( DataValidationType.DECIMAL, [DataValidationOperator.BETWEEN, '1', '10'], true );

setOptions()

setOptions(options): FDataValidation

Set the options for the data validation rule

Parameters

ParameterTypeDescription
optionsIDataValidationRuleOptionsThe options to set for the data validation rule

Returns

FDataValidation

The current instance for method chaining

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); dataValidation.setOptions({ allowBlank: true, showErrorMessage: true, error: 'Please enter a valid value' });

setRanges()

setRanges(ranges): FDataValidation

Set the ranges to the data validation rule

Parameters

ParameterTypeDescription
rangesFRange[]New ranges array

Returns

FDataValidation

The current instance for method chaining

Example

const dataValidation = univerAPI .getActiveWorkbook() .getActiveWorksheet() .getActiveRange() .getDataValidation(); const range = FRange.create('Sheet1', 'A1:B10'); dataValidation.setRanges([range]);