import org.apache.poi.hssf.usermodel.DVConstraint; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFDataValidation; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; // 初始一个workbook HSSFWorkbook workbook = new HSSFWorkbook(); // 创建一个sheet HSSFSheet sheet= workbook.createSheet(); // 创建行 HSSFRow row= sheet.createRow(0); // 创建列 HSSFCell cell= row.createCell(index++); // 准备下拉列表数据 List<BasicDBObject> options = (List<BasicDBObject>) bo.get("options"); String[] optionArr = new String[options.size()]; for (int i = 0; i < options.size(); i++) { optionArr[i] = options.get(i).getString("value"); } // 设置第一列的1-10000行为下拉列表 CellRangeAddressList regions = new CellRangeAddressList(0, 10000, 0, 0); // 创建下拉列表数据 DVConstraint constraint = DVConstraint.createExplicitListConstraint(optionArr); // 绑定 HSSFDataValidation dataValidation = new HSSFDataValidation(regions, constraint); sheet.addValidationData(dataValidation);