Free Support Forum -

Marlett Checkboxes - validating 'a' and 'r'

I’m implementing Marlett Checkboxes.

How do I make the validation only allow the character ‘a’ or ‘r’ in the cell?


Please see the following sample code that demonstrates on how to add a List validation to a range of cells that allows only to enter “a” or “r” in the cells for your reference:
Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet1 = workbook.Worksheets[0];
int i = workbook.Worksheets.Add();
Worksheet worksheet2 = workbook.Worksheets[i];
ValidationCollection validations = worksheet1.Validations;
Validation validation = validations[validations.Add(CellArea.CreateCellArea(0,0,4,0))]; //CellArea is A1:A5
validation.Type = Aspose.Cells.ValidationType.List;
validation.Operator = OperatorType.None;
//Comment this line if you do not need drop downs attached to the cell(s)
validation.InCellDropDown = true;
validation.Formula1 = “a,r”;
validation.ShowError = true;
validation.AlertStyle = ValidationAlertType.Stop;
validation.ErrorTitle = “Error”;
validation.ErrorMessage = “Please add appropriate char (a/r)”;


If you still have any issue or other requirements, please create an Excel file manually in Ms Excel and perform your desired validation or conditional formattings to be applied on the cell, save the file and post us here, we will check on how to do it via Aspose.Cells APIs.

Thank you.