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.
Thanks,
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.