POI操作 设置下拉值

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

 final HSSFWorkbook workbook = new HSSFWorkbook(fis);
        final IntradayCustomerParamTemplateSpec customerTemplateSpec = IntradayCustomerParamTemplateSpec.INSTANCE;
        final HSSFSheet customerSheet = workbook.getSheet(customerTemplateSpec.getSheetName());
        if (batchCount != 0) {
            Row row = customerSheet.getRow(1);
            for (int i = 1; i < batchCount + 1; i++) {
                Cell cell = row.createCell(IntradayCustomerParamTemplateSpec.PRIORITY_COL + i);
                cell.setCellValue("batch " + i);
                cell.setCellStyle(row.getCell(IntradayCustomerParamTemplateSpec.PRIORITY_COL).getCellStyle());
            }
        }
        CellRangeAddressList regions = new CellRangeAddressList(2, 65535, IntradayCustomerParamTemplateSpec.PRIORITY_COL+1,IntradayCustomerParamTemplateSpec.PRIORITY_COL+batchCount);   
        String [] list={"Y","N"};
        DVConstraint constraint = DVConstraint.createExplicitListConstraint(list); //将list中的内容写入到excel中  
        HSSFDataValidation data_validation = new HSSFDataValidation(regions,constraint); //绑定下拉菜单和作用域  
        customerSheet.addValidationData(data_validation);

转载于:https://my.oschina.net/u/3503613/blog/1503713

你可能感兴趣的:(POI操作 设置下拉值)