我正在通过java代码构建动态下拉,它工作得非常好。 我正在运行的代码是:
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Data Validation");
XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
dvHelper.createExplicitListConstraint(new String[]{"0000011", "0000021", "0000031"});
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
XSSFDataValidation validation = (XSSFDataValidation)dvHelper.createValidation(
dvConstraint, addressList);
validation.setShowErrorBox(true);
validation.setSuppressDropDownArrow(true);
sheet.addValidationData(validation);
下拉正常,但当我从下拉00000
中选择任何一个值时会自动删除,只显示11,但我希望选择值为0000011
从下拉。
放置值显示为0000011
但在选择后会显示11
。如果我们可以将细胞类型更改为文本,它可能会有所帮助,或者其他方式但是如何做到这一点?
答案 0 :(得分:1)
// setting cell type as string to avoid removing 00000 from drop down
CellStyle textStyle = workbook.createCellStyle();
textStyle.setDataFormat((short)BuiltinFormats.getBuiltinFormat("text"));
sheet.setDefaultColumnStyle(0, textStyle);