final int dstCol = dstCell.getColumnIndex();
final List<? extends DataValidation> dataValidations= BookHelper.getDataValidations(srcSheet);
if (dstSheet.equals(srcSheet)) {
for(DataValidation dataValidation : dataValidations) {
CellRangeAddressList addrList = dataValidation.getRegions();
boolean srcInRange = false;
boolean dstInRange = false;
for(int j = addrList.countRanges(); --j >= 0;) {
final CellRangeAddress addr = addrList.getCellRangeAddress(j);
if (!srcInRange) {
srcInRange = addr.isInRange(srcRow, srcCol);
}
if (!dstInRange) {
dstInRange = addr.isInRange(dstRow, dstCol);
}
if (srcInRange && dstInRange) { //no need to copy
break;
}
}
if (!srcInRange) { //this validation is not associated to source cell
continue;
}
if (!dstInRange) { //so we shall copy this data validation to dst cell
dataValidation.getRegions().addCellRangeAddress(dstRow, dstCol, dstRow, dstCol);
}
}
} else {
final DataValidationHelper helper = dstSheet.getDataValidationHelper();
for(DataValidation dataValidation : dataValidations) {
CellRangeAddressList addrList = dataValidation.getRegions();
boolean srcInRange = false;
for(int j = addrList.countRanges(); --j >= 0;) {
final CellRangeAddress addr = addrList.getCellRangeAddress(j);
if (!srcInRange) {
srcInRange = addr.isInRange(srcRow, srcCol);
}
if (srcInRange) {
break;
}
}
if (!srcInRange) { //this validation is not associated to source cell
continue;
}
//so we shall copy this data validation to dst cell
final DataValidationConstraint constraint = BookHelper.getConstraint(dataValidation);
DataValidation dstDataValidation = BookHelper.getDataValidationByConstraint(constraint, getDataValidations(dstSheet));
if (dstDataValidation == null) {
final CellRangeAddressList dstAddrList = new CellRangeAddressList(dstRow, dstCol, dstRow, dstCol);
dstDataValidation = helper.createValidation(constraint, dstAddrList);
dstSheet.addValidationData(dstDataValidation);
} else {
CellRangeAddressList dstAddrList = dstDataValidation.getRegions();
dstAddrList.addCellRangeAddress(dstRow, dstCol, dstRow, dstCol);
}
}
}
}