Following code snippet will help you to validate cell value.Please refer to the direct link for more information about data validation. If still you face any problem feel free to contact us.
Code snippet:
Workbook workBook = new Workbook();
FileStream fileStream = null;
Worksheet workSheet = workBook.Worksheets[0];
Validations validations = workSheet.Validations;
//Creating a Validation object
Validation validation = validations[validations.Add()];
//Setting the custom validation type
validation.Type = Aspose.Cells.ValidationType.Custom;
validation.AlertStyle = ValidationAlertType.Stop;
validation.ErrorMessage = "This cell cannot be changed";
validation.Formula1 = "=A1";
validation.ShowError = true;
CellArea area = new CellArea();
area.StartRow =0;
area.EndRow = 0;
area.StartColumn = 0;
area.EndColumn = 0;
validation.AreaList.Add(area);
workBook.Save(@"d:\\test\\Custom_Protection.xls", FileFormatType.Excel2003);
If you set formula as "=A1", the formula will be different in each cell. The formula will be changed according to each cell.
If you want the formula to be same in each cell, use formula as "=$A$1". Where reference with "$" means, it's an absolute reference and reference without "$", means it is relative reference.
Note: In case of relative reference, the change will automatically be reflected in Validation, ConditionalFormatting, SharedFormula.