poi操作excel设置数据有效性
private void setDataValidationList(short firstRow,short endRow,short firstCol, short endCol,String data,HSSFSheet sheet ){ //设置下拉列表的内容 String[] textlist=data.split(","); for(int i=0;i<textlist.length;i++){ System.out.println(textlist[i]); } //加载下拉列表内容 DVConstraint constraint=DVConstraint.createExplicitListConstraint(textlist); //设置数据有效性加载在哪个单元格上。 //四个参数分别是:起始行、终止行、起始列、终止列 CellRangeAddressList regions=new CellRangeAddressList(firstRow,endRow,firstCol,endCol); /* CellRangeAddressList regions = new CellRangeAddressList( 6,5, 6,5);*/ //数据有效性对象 HSSFDataValidation data_validation_list = new HSSFDataValidation(regions, constraint); data_validation_list.setSuppressDropDownArrow(false); sheet.addValidationData(data_validation_list); }
Don’t hurry say have no choice, perhaps, next intersection will meet hope.