如何让用户只选择下拉列表中的一个值,而不是在Excel工作表中输入自己的值。我正在使用Java库Apache-POI
答案 0 :(得分:2)
如果您使用HSSFWorkbook,请使用以下
DVConstraint dvConstraint =
DVConstraint.createExplicitListConstraint(new String [] {“ABC”}); DataValidation dataValidation = new HSSFDataValidation(programList,dvConstraint); dataValidation.setSuppressDropDownArrow(真); dataValidation.setShowErrorBox(真); dataValidation.setShowPromptBox(真);
targetSheet.addValidationData(dataValidation);
For XSSFWorkbook, use as below
DataValidationHelper validationHelper=new XSSFDataValidationHelper(targetSheet);
DataValidationConstraint constraint =validationHelper.createExplicitListConstraint(new String[]{"ABC"});
DataValidation dataValidation = validationHelper.createValidation(constraint, programList);
dataValidation.setSuppressDropDownArrow(true);
dataValidation.setShowErrorBox(true);
dataValidation.setShowPromptBox(true);
targetSheet.addValidationData(dataValidation);