This project has moved. For the latest updates, please go here.

Data Validation

            var wb = new XLWorkbook();
            var ws = wb.Worksheets.Add("Data Validation");

Decimal between 1 and 5


            ws.Cell(1, 1).DataValidation.Decimal.Between(1, 5);

Whole number equals 2, use an error message


            var dv1 = ws.Range("A2:A3").DataValidation;

            dv1.ErrorStyle = XLErrorStyle.Warning;
            dv1.ErrorTitle = "Number out of range";
            dv1.ErrorMessage = "This cell only allows the number 2.";

Date after the millenium, use an input message

[image:DataValidation3.jpg] [image:DataValidation5.jpg]

            var dv2 = ws.Cell("A4").DataValidation;
            dv2.Date.EqualOrGreaterThan(new DateTime(2000, 1, 1));

            dv2.InputTitle = "Can't party like it's 1999.";
            dv2.InputMessage = "Please enter a date in this century.";

From a list


            ws.Cell("C1").Value = "Yes";
            ws.Cell("C2").Value = "No";

Last edited May 25, 2012 at 3:10 PM by MDeLeon, version 5