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(起始行号,终止行号, 起始列号,终止列号)

 

posted @ 2022-03-22 09:48  无效_rank  阅读(580)  评论(0)    收藏  举报