Negative number validations for Aspose.Cells.Worksheet

Hi,

We are validating the positive decimal numbers by using below code for Aspose.Cells.Worksheet.

FileStream fstream = new FileStream(Server.MapPath(sFilepath), FileMode.Open);

Aspose.Cells.Workbook wbook = new Aspose.Cells.Workbook();

wbook.Open(fstream);

Aspose.Cells.Worksheet wPASheet = wbook.Worksheets[2];

ValidationCollection validationsPA = wPASheet.Validations;

Aspose.Cells.Validation validationPA = validationsPA[validationsPA.Add()];

validationPA.Type = Aspose.Cells.ValidationType.Decimal;

validationPA.Operator = OperatorType.GreaterOrEqual;

validationPA.Value1 = 0;

Could you please let us know how can we validate both positive and negative decimal numbers for Aspose.Cells.Worksheet.

Hi,


Please see the sample code snippet for your reference:

Samlpe code:

Workbook workbook = new Workbook();
Worksheet ExcelWorkSheet = workbook.Worksheets[0];

ValidationCollection validations = ExcelWorkSheet.Validations;

Validation validation = validations[validations.Add()];

validation.Type = ValidationType.Decimal;

validation.Operator = OperatorType.Between;

validation.Formula1 = “-9999.99”;

validation.Formula2 = “9999.99”;

validation.ErrorMessage = “Please enter a valid integer or decimal number”;

CellArea area;

area.StartRow = 0;

area.EndRow = 5;

area.StartColumn = 0;

area.EndColumn = 0;

validation.AreaList.Add(area);
//…


For further reference, please see the document sub-topic:
http://www.aspose.com/docs/display/cellsnet/Data+Filtering+and+Validation#DataFilteringandValidation-decimal

Thank you.

Thanks for your reply.

But we don’t want restrict the users to enter values in specific range. Cell has to allow all positive and negative decimals.

Let us know how can we achieve this.

Thanks

Hi,


Well, I think you may define the full range of Decimal type, e.g

// Set the lower and upper limits.
validation.Formula1 = Decimal.MinValue.ToString();
validation.Formula2 = Decimal.MaxValue.ToString();