This project has moved and is read-only. For the latest updates, please go here.

Help on datavalidation for integer/decimal only

Nov 20, 2012 at 6:55 AM

Hi,

I am trying to have cells with integer/decimal only. Here is the link to actual excel datavalidation that i want to achieve.

http://www.techonthenet.com/excel/cells/validation2_2010.php

Currently trying out the integer.

Here is my code

var validation3 = ws.DataValidations.AddIntegerValidation("AI2:AI" + rowCount.ToString());
validation3.ShowErrorMessage = true;
validation3.ErrorStyle = OfficeOpenXml.DataValidation.ExcelDataValidationWarningStyle.warnivalidation3.ErrorTitle = "An invalid value was entered";
validation3.Error = "Must be integer only";

validation3.Operator = OfficeOpenXml.DataValidation.ExcelDataValidationOperator.greaterThan;

When it runs it says i am missing some formula. I believe it is .Formula but not sure how the structure is. Any help ? Thanks.

Nov 21, 2012 at 6:23 AM

Hi,

The code you have supplied does add an integer validation to the range "AI2:AI..." and uses the greaterthan operator. But you also need to add the integer value it self to the validation (that it should be greater than).

it is done this way:

validation.Formula.Value = 5;

 

...if you want the validation to only allow values above 5.

For more examples on DataValidation, download the samles (at the downloads section) and check out sample 11.

/Mats