Hi,
I want to produce files with cutom data validation using Aspose Cells v.17.1.0.
I am testing this for both xls and xlsx files and when used for xls the resutling data validation appears as custom but has no formula stored, so something is not working.
Is it so that Excel 2003 did not support custom data validations?
Or am I doing something wrong in the code snippet below? (in cell A1 I want to require a text that is longer than 2 characters but shorter than 10. And if the user chooses to enter a formula that does not evaluate and gives an error code I want to accept that as well because I will ignore such cells anyway)
Worksheet ws = wb.getWorksheets().get(0);
int col1 = 0;
int col2 = 0;
int row1 = 0;
int row2 = 0;
String formula1 = “IF(ISERROR(A1),TRUE,AND(LEN(A1)<10,LEN(A1)>2))”;
ValidationCollection validations = ws.getValidations();
CellArea area = new CellArea();
area.StartColumn = col1;
area.StartRow = row1;
area.EndColumn = col2;
area.EndRow = row2;
Validation validation = validations.get(validations.add(area));
validation.setType(ValidationType.CUSTOM);
validation.setInCellDropDown(true);
validation.setIgnoreBlank(true);
validation.setFormula1(formula1);
validation.setErrorTitle(“errorTitle”);
validation.setErrorMessage(“errorMessage”);
<span style=“background-color: rgb(255, 255, 255); font-family: “Courier New”;”>wb.save(<span style=“font-family: “Courier New”; color: rgb(0, 128, 0); font-weight: bold;”>“asposeValidation.xls”<span style=“background-color: rgb(255, 255, 255); font-family: “Courier New”;”>);
Best regards
Claes