Hi,
Well, I think you may use List data validation, Aspose.Cells does support all the validation types that MS Excel supports. Please see the following sample code, I have dynamically created data list validation, I used your Excel file as the input source and applied the validation on A3:A6 cells in the second sheet.
Sample code:
Workbook workbook = new Workbook(“e:\test2\DynamicRangeExample.xlsx”);
// Get the first worksheet.
Worksheet worksheet1 = workbook.Worksheets[0];
//Get the second worksheet
Worksheet worksheet2 = workbook.Worksheets[1];
// Get the validations collection.
ValidationCollection validations = worksheet2.Validations;
// Create a new validation to the validations list.
Validation validation = validations[validations.Add()];
// Set the validation type.
validation.Type = Aspose.Cells.ValidationType.List;
// Set the operator.
validation.Operator = OperatorType.None;
// Set the in cell drop down.
validation.InCellDropDown = true;
// Set the formula1.
validation.Formula1 = “=DepartmentNames”;
// Enable it to show error.
validation.ShowError = true;
// Set the alert type severity level.
validation.AlertStyle = ValidationAlertType.Stop;
// Set the error title.
validation.ErrorTitle = “Error”;
// Set the error message.
validation.ErrorMessage = “Please select a valid department”;
// Specify the validation area A3:A6.
CellArea area;
area.StartRow = 2;
area.EndRow = 5;
area.StartColumn = 0;
area.EndColumn = 0;
// Add the validation area.
validation.AreaList.Add(area);
// Save the Excel file.
workbook.Save(“e:\test2\outvalidationtypelist1.xlsx”);
And, please see the document for your complete reference on Data Validation and how you can use them using Aspose.Cells APIs:
Thank you.