2

I want to write a code to populate a restricted excel sheet in which all the cells in excel must only contain the allowed values as drop down list ( as checkboxes i.e user can select more than one value from the drop down list to fill the excel sheet .So user have to select the multiple values from the list only. He cannot write something else) .I have written the code in which user is able to select only one value.I have used Apache Poi.

        XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheet);

        String[] arrayList = allowedValues.toArray(new String[allowedValues.size()]);

        XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(arrayList);

        CellRangeAddressList addressList = new CellRangeAddressList(row.getRowNum() + 1, 10000, cell.getColumnIndex(), cell.getColumnIndex());

        XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);

        validation.setShowErrorBox(true);

        validation.createErrorBox("ERROR MESSAGE:Invalid Data", "Please provide valid data in the drop down list.");

        sheet.addValidationData(validation);

  • 1
    How would you do this using `Excel`'s `GUI`? `Apache poi` is not able to do what `Excel` itself in not able to do. As far as I know, there is no multi select drop down list available as data validation list in `Excel`. – Axel Richter Nov 21 '19 at 13:55

0 Answers0