Example usage for org.apache.poi.ss.usermodel DataValidationHelper createExplicitListConstraint

List of usage examples for org.apache.poi.ss.usermodel DataValidationHelper createExplicitListConstraint

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel DataValidationHelper createExplicitListConstraint.

Prototype

DataValidationConstraint createExplicitListConstraint(String[] listOfValues);

Source Link

Usage

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.util.ExcelGeneratorUtils.java

License:Open Source License

/**
 * Creates a dropdown box for each cell in the specified {@code addressList}.
 * /* w  ww  . java  2 s.c  o m*/
 * @param sheet the sheet to add the dropdown box to
 * @param addressList the cell range to add the dropdown box to
 * @param values the values to be shown in dropdown box
 */
public static void createDropdownWithValues(Sheet sheet, CellRangeAddressList addressList,
        List<String> values) {
    DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
    String[] valuesList = values.toArray(new String[values.size()]);
    DataValidationConstraint dvConstraint = dataValidationHelper.createExplicitListConstraint(valuesList);
    DataValidation dataValidation = dataValidationHelper.createValidation(dvConstraint, addressList);
    // There is an error in the interpretation of the argument of setSuppressDropDownArrow in POI 3.9
    // for XSSF Workbooks. The arrow is suppressed if the argument is set to 'false' instead of 'true'.
    // In HSSF Workbooks the method works as designed.
    // Luckily in both cases the default behavior is, that the arrow is displayed. So we can skip the explicit setting of this behavior.
    // SKIP THIS: dataValidation.setSuppressDropDownArrow(false);

    sheet.addValidationData(dataValidation);
}

From source file:edu.casetools.rcase.extensions.excel.control.Exporter.java

License:Open Source License

private DataValidation createExcel2007CellStyle(Sheet sheet, String[] possibleValues,
        CellRangeAddressList addressList) {
    DataValidation validation;//from www  .  j ava 2s. c  o  m
    DataValidationConstraint constraint;
    DataValidationHelper validationHelper;
    validationHelper = new XSSFDataValidationHelper((XSSFSheet) sheet);

    constraint = validationHelper.createExplicitListConstraint(possibleValues);
    validation = validationHelper.createValidation(constraint, addressList);
    validation.setEmptyCellAllowed(false);
    validation.setShowErrorBox(true);
    validation.setErrorStyle(0);
    return validation;
}