Data Validation

Add input rules to cells to restrict what values users can enter.

Whole Number Validation

using DotnetPoi.XSSF.UserModel;
using DotnetPoi.SS.UserModel;

sheet.AddDataValidation(new XSSFDataValidation
{
    Sqref = "C4:C6",              // cell range to validate
    Type = DataValidationType.Whole,
    Operator = DataValidationOperator.Between,
    Formula1 = "1",
    Formula2 = "100",
    PromptTitle = "Quantity",
    PromptMessage = "Enter a whole number from 1 to 100.",
    ErrorTitle = "Invalid quantity",
    ErrorMessage = "Quantity must be between 1 and 100."
});

Validation Types

TypeDescription
WholeInteger numbers
DecimalDecimal numbers
ListValue must be in a list
DateDate values
TimeTime values
TextLengthText character count
CustomCustom formula

Operators

Between, NotBetween, Equal, NotEqual, GreaterThan, LessThan, GreaterOrEqual, LessOrEqual.

Full Runnable Example

See examples/UsageSamples/Program.cs (CreateSpreadsheet):

examples/UsageSamples