POI 添加下拉框
WorkBook workbook = new WorkBook(); Sheet sheet = workbook.creatSheet("sheet1"); String[] types = {"1","2","3"} //设置行列范围(资源类型) CellRangeAddressList addressList = new CellRangeAddressList(1,500,1,1); //设置下拉框数据 DataValidationHelper helper = sheet.getDataValidationHelper();
//数据有效性 DataValidationConstraint constraint = helper.createExplicitListConstraint(typs);
//设置下拉框数据
DataValidation validation = helper.createValidation(constraint,helper)
//解决兼容性问题 if(dataValidation instanceof XSSFDataValidation) {
//设置只能选下拉菜单里的值不能随便输入 dataValidation.setSuppressDropDownArrow(true); dataValidation.setShowErrorBox(true); }else { dataValidation.setSuppressDropDownArrow(false); } sheet.addvalidationData(dataValidation);
相关参数
CellRangeAddress(起始行号,终止行号, 起始列号,终止列号)
浙公网安备 33010602011771号