Class Validation

Validation class

Represents data validation.settings.

public class Validation

Properties

NameDescription
AlertStyle { get; set; }Represents the validation alert style.
Areas { get; }Gets all CellArea which contain the data validation settings.
ErrorMessage { get; set; }Represents the data validation error message.
ErrorTitle { get; set; }Represents the title of the data-validation error dialog box.
Formula1 { get; set; }Represents the value or expression associated with the data validation.
Formula2 { get; set; }Represents the value or expression associated with the data validation.
IgnoreBlank { get; set; }Indicates whether blank values are permitted by the range data validation.
InCellDropDown { get; set; }Indicates whether data validation displays a drop-down list that contains acceptable values.
InputMessage { get; set; }Represents the data validation input message.
InputTitle { get; set; }Represents the title of the data-validation input dialog box.
Operator { get; set; }Represents the operator for the data validation.
ShowError { get; set; }Indicates whether the data validation error message will be displayed whenever the user enters invalid data.
ShowInput { get; set; }Indicates whether the data validation input message will be displayed whenever the user selects a cell in the data validation range.
Type { get; set; }Represents the data validation type.
Value1 { get; set; }Represents the first value associated with the data validation.
Value2 { get; set; }Represents the second value associated with the data validation.

Methods

NameDescription
AddArea(CellArea)Applies the validation to the area.
AddArea(CellArea, bool, bool)Applies the validation to the area.
AddAreas(CellArea[], bool, bool)Applies the validation to given areas.
Copy(Validation, CopyOptions)Copy validation.
GetFormula1(bool, bool)Gets the value or expression associated with this validation.
GetFormula1(bool, bool, int, int)Gets the value or expression associated with this validation for specific cell.
GetFormula2(bool, bool)Gets the value or expression associated with this validation.
GetFormula2(bool, bool, int, int)Gets the value or expression associated with this validation for specific cell.
GetListValue(int, int)Get the value for list of the validation for the specified cell.
GetValue(int, int, bool)Get the value of validation on the specific cell.
RemoveACell(int, int)Remove the validation settings in the cell.
RemoveArea(CellArea)Remove the validation settings in the range.
RemoveAreas(CellArea[])Removes this validation from given areas.
SetFormula1(string, bool, bool)Sets the value or expression associated with this validation.
SetFormula2(string, bool, bool)Sets the value or expression associated with this validation.

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using System;

    public class ValidationDemo
    {
        public static void ValidationExample()
        {
            // Create a new workbook
            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];

            // Define a cell area for the validation
            CellArea area = CellArea.CreateCellArea(0, 0, 1, 1);

            // Access the validations collection
            ValidationCollection validations = worksheet.Validations;

            // Add a new validation to the collection
            int validationIndex = validations.Add(area);
            Validation validation = validations[validationIndex];

            // Set validation properties
            validation.Type = ValidationType.WholeNumber;
            validation.Operator = OperatorType.Between;
            validation.Formula1 = "3";
            validation.Formula2 = "1234";
            validation.InputMessage = "Please enter a whole number between 3 and 1234.";
            validation.InputTitle = "Whole Number Validation";
            validation.ErrorMessage = "The value must be a whole number between 3 and 1234.";
            validation.ErrorTitle = "Invalid Input";
            validation.ShowInput = true;
            validation.ShowError = true;
            validation.IgnoreBlank = true;
            validation.InCellDropDown = true;

            // Save the workbook
            workbook.Save("ValidationExample.xlsx");

            return;
        }
    }
}

See Also