poi 导出excel带下拉框
DataValidationHelper helper =sheet.getDataValidationHelper(); List<String> nameList = new ArrayList<String>(); DataValidationConstraint constraint = helper.createExplicitListConstraint(nameList.toArray(new String[nameList.size()])); CellRangeAddressList regions = new CellRangeAddressList(1, 65535, 3, 3); DataValidation dataValidation = helper.createValidation(constraint, regions); dataValidation.createErrorBox("错误提示", "请从下拉框中选择");
sheet.addValidationData(dataValidation);
限制范围
constraint = helper.createIntegerConstraint(OperatorType.BETWEEN, "0", "9999");
regions = new CellRangeAddressList(1, 65535, 18, 18);
dataValidation = helper.createValidation(constraint, regions);
dataValidation.createErrorBox("错误提示", "发货数量必须在0~9999之间");
sheet.addValidationData(dataValidation);
constraint = helper.createDateConstraint(OperatorType.BETWEEN, "2016-12-12", "2099-12-31", "yyyy-MM-dd"); regions = new CellRangeAddressList(1, 65535, 15, 17); dataValidation = helper.createValidation(constraint, regions); dataValidation.createErrorBox("错误提示", "日期格式为yyyy-MM-dd"); sheet.addValidationData(dataValidation);