public XSSFWorkbook exportExcel()throws Exception{
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("下拉列表");
String[] rank = new String[]{"高","中","低"};
XSSFDataValidationHelper validationHelper = (XSSFDataValidationHelper) sheet.getDataValidationHelper();
XSSFDataValidationConstraint daConstraint = (XSSFDataValidationConstraint) validationHelper.createExplicitListConstraint(rank);
CellRangeAddressList addressList = null;
XSSFDataValidation validation = null;
for(int i = 0;i < 100;i++){
addressList = new CellRangeAddressList(i, i, 0, 0);
validation = (XSSFDataValidation) validationHelper.createValidation(
daConstraint, addressList);
validation.setSuppressDropDownArrow(true);
validation.setShowErrorBox(true);
sheet.addValidationData(validation);
}
return workbook;
}
网友评论