How to create a dependent drop down list using [Apache POI]

How to create a dependent drop down list using [Apache POI]

Here I am creating one excel template using [Apache POI] in that user can fill data. In that two drop down list are there. Want to create a drop down list that depends on previous cell's drop down. For example: If I select veg category in cell 3, and "rice, curd, milk" items will appear in the dependent drop down list in cell 4. Codes are below.

Here collecting data

List<InternetItemResponse> internetItems = internetItemService.getAllByHotelId(hotelId);
if (CollectionUtils.isNotEmpty(internetItems)) {
String[] itemsName = new String[internetItems.size()];
String[] itemsCategory = new String[internetItems.size()];
String itemName;
String itemCategory;
Map<String, Set<String>> categoryVsItemName = new HashMap<>();
Set<String> itemList;
for (int i = 0; i < internetItems.size(); i++) {
    InternetItemResponse itemResponse = internetItems.get(i);
    if (itemResponse != null) {
        itemCategory = itemResponse.getCategory();
        if (!StringUtils.isEmpty(itemCategory)) {
            itemsCategory[i] = itemCategory;
            itemName = itemResponse.getTitle();
            itemsName[i] = itemName;
            if (CollectionUtils.isEmpty(categoryVsItemName.get(itemCategory))) {
                itemList = new HashSet<>();
                itemList.add(itemName);
                categoryVsItemName.put(itemCategory, itemList);
            } else {
                categoryVsItemName.get(itemCategory).add(itemName);
            }
        }
    }
}

}

Assigning the data in drop down

// Setting drop down values
for (int i = 0; i < headerColumns.length; i++) {
    if (i == 3) {
        XSSFDataValidationHelper mealdvHelper = new XSSFDataValidationHelper((XSSFSheet) sheet);
        XSSFDataValidationConstraint mealdvConstraint = (XSSFDataValidationConstraint) mealdvHelper
                .createExplicitListConstraint(itemsCategory);
        // CellRangeAddressList(int firstRow, int lastRow, int firstCol, int lastCol)
        CellRangeAddressList addressListmeal = new CellRangeAddressList(1, 99, i, i);
        XSSFDataValidation categoryDataValidation = (XSSFDataValidation) mealdvHelper
                .createValidation(mealdvConstraint, addressListmeal);
        categoryDataValidation.setShowErrorBox(true);
        categoryDataValidation.setSuppressDropDownArrow(true);
        categoryDataValidation.setShowPromptBox(true);
        sheet.addValidationData(categoryDataValidation);
    } else if (i == 4) {
        XSSFDataValidationHelper rmCategorydvHelper = new XSSFDataValidationHelper((XSSFSheet) sheet);
        XSSFDataValidationConstraint rmCategorydvConstraint = (XSSFDataValidationConstraint) rmCategorydvHelper
                .createExplicitListConstraint(itemsName);
        CellRangeAddressList addressListrmCategory = new CellRangeAddressList(1, 99, i, i);
        XSSFDataValidation itemNameValidation = (XSSFDataValidation) rmCategorydvHelper
                .createValidation(rmCategorydvConstraint, addressListrmCategory);
        itemNameValidation.setShowErrorBox(true);
        itemNameValidation.setSuppressDropDownArrow(true);
        itemNameValidation.setShowPromptBox(true);
        sheet.addValidationData(itemNameValidation);
    }
}
View Answers

Ads









Related Tutorials/Questions & Answers:
How to create a dependent drop down list using [Apache POI]
How to create a dependent drop down list using [Apache POI]
Advertisements
Dependent drop down list
JSP Dependent Drop Down Menu
How to pass parameter through drop down list using session management in jsp??
dynamic drop down list
How to insert multiple drop down list data in single column in sql database using servlet
view data from database using drop down list
how to retreive data dynamically from mysql to drop down list
Get values in drop down list
Excel Cell Drop Down List
Dependant & dynamic drop down list
Drop down list from database
store values of drop down list box in database
Java Swing dependent JList
how to make drop down list in JSF & fetch data Item from database
Add/Remove Rows Dynamically with drop down list in html table using php
Drop Down
Display related data in other drop down list on selecting one data in one drop down list
Dependant & dynamic drop down list - Follow up
drop down
How to create runtime drag and drop form builder using asp.net mvc and jquery
how to store multiple values from drop down in database where i am using java struts 1.3
Drop Down Reloads again in IE..How to prevent this?
drop down menu
Passing Multi select list box values using ajax to get values to dependent list box
Choice Option (Combo) In Java
How to create a Student data base using Linked List in java
Drop Down reload in IE
retrive the data from access database to drop down list box in jsp
how to create using jsp

Ads