poi设置下拉框

1.下拉框数据较少时

String[] strs = new String[]{"结算等级1","结算等级2","结算等级3","结算等级4","结算等级5","结算等级6"};
			            CellRangeAddressList regions = new CellRangeAddressList(1, rowIdx - 1, i, i);
			            DVConstraint constraint = DVConstraint.createExplicitListConstraint(strs);
			            HSSFDataValidation dataValidation = new HSSFDataValidation(regions, constraint);
			            sheet.addValidationData(dataValidation);



2.下拉框数据很多时

Sheet sheetHid = wb.createSheet("hidden");
			wb.setSheetHidden(wb.getSheetIndex("hidden"), true);
			
			
			Cell cellHid = null;

	        for (int h = 0, length= MallAr.length; h < length; h++) { 
	           String name = MallAr[h]; 
	           Row rowHid = sheetHid.createRow(h); 
	           cellHid = rowHid.createCell(0); 
	           cellHid.setCellValue(name); 
	           
	        } 
			Name namedCell = wb.createName(); 
			namedCell.setNameName("Mall"); 
			namedCell.setRefersToFormula("hidden!$A$1:$A$" + MallAr.length); 
            DVConstraint constraintMall = DVConstraint.createFormulaListConstraint("Mall");


CellRangeAddressList regions = new CellRangeAddressList(1, rowIdx - 1, i, i);
			            HSSFDataValidation dataValidation = new HSSFDataValidation(regions, constraintMall);
			            sheet.addValidationData(dataValidation);

猜你喜欢

转载自newjava-sina-cn.iteye.com/blog/2406799