XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(
destinationSheet);
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper
.createIntegerConstraint(OperatorType.EQUAL, "0", "10");
CellRangeAddressList addressList = new CellRangeAddressList(7,
destinationSheet.getLastRowNum() + 1, 9, destinationSheet
.getRow(0).getLastCellNum());
XSSFDataValidation validation = (XSSFDataValidation) dvHelper
.createValidation(dvConstraint, addressList);
validation.setErrorStyle(ErrorStyle.STOP);
validation.createErrorBox("Error", "Only numeric values are allowed");
destinationSheet.addValidationData(validation);
我使用了上面的代码,它不起作用并且仍然接受单元格上的任何内容。如果我是对的,这条线就是罪魁祸首。
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper
.createIntegerConstraint(OperatorType.EQUAL, "0", "10");
基本上,我希望 Cell 范围中的单元格只接受 0 和 10 并限制字母字符。我也试过OperatorType.BETWEEN
但没有运气。
这是我的参考。忙碌的开发者