我正在使用下面的代码来限制用户输入少于 10 个字符,但是当我将数据复制并粘贴到单元格中时,它会覆盖验证。我该如何解决这个问题?
cell = row.createCell(colIndex++);
CellRangeAddressList cellRangeAddressListCur1 = new CellRangeAddressList();
cellRangeAddressListCur1.addCellRangeAddress(cell.getRowIndex(), cell.getColumnIndex(), cell.getRowIndex(), cell.getColumnIndex());
DVConstraint dvConstraint = DVConstraint.createNumericConstraint(DVConstraint.ValidationType.TEXT_LENGTH, OperatorType.LESS_THAN, "10", null);
HSSFDataValidation xssfDataValidation = new HSSFDataValidation(cellRangeAddressListCur1, dvConstraint);
xssfDataValidation.setErrorStyle(HSSFDataValidation.ErrorStyle.STOP);
xssfDataValidation.createErrorBox("Error Message", "Please enter less than 10 characters");
xssfDataValidation.setSuppressDropDownArrow(false);
sheet.addValidationData(xssfDataValidation);
cell.setCellStyle(textCellStyle);