jeudi 21 novembre 2019

selecting multiple values at once from the drop down list in a cell of an excel sheet using Apache Poi

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);




Aucun commentaire:

Enregistrer un commentaire