Right at the start I should say that I have never done this myself and that I
got this piece of code from a discussion that was led by Pierre Lavignotte
and contributed to by a few other users so can claim no credit at all if it
works.

Having said all of that, I think that you need to look at the
HSSFDataValidation class. As far as I can see, it uses a named range of
cells to provide the basis for the validation of the input a user makes.
Further, it seems that it is possible to make this validation work in a few
different ways, one of whihc is to use a drop down list.

I have not tried or tested this code myself - it was always something I
intended to do when I got the time - so can make no promises for it.
Nevertheless, here is the code that the group worked on;

HSSFSheet sheet = wb.getSheet("Sheet1");
HSSFName namedRange = wb.createName();
namedRange.setNameName("NAMEDAREA");
namedRange.setReference("Sheet1!$A$1:$A$2");

int start_row = (short)0;
String strFormula = "$A$1:$A$2";
HSSFDataValidation data_validation = new
HSSFDataValidation((short)(start_row),(short)1,(short)(start_row),(short)1);
data_validation.setDataValidationType(HSSFDataValidation.DATA_TYPE_LIST);
data_validation.setFirstFormula(strFormula);
data_validation.setSecondFormula(null);
data_validation.setExplicitListFormula(true);
data_validation.setSurppressDropDownArrow(false);
data_validation.setEmptyCellAllowed(true);
data_validation.setShowPromptBox(false);
dta_validation.createErrorBox("Invalid input !", "Something is wrong. check
condition!");
sheet.addValidationData(data_validation);

Good luck and I hope it works for you.


TRSP wrote:
> 
> Hi,
> 
> I am using Jakarta POI3.5 to generate an excel spreadsheet. I need to have
> a drop down list box in a column in the excel sheet to restrict the user
> in changing the value of that particular cell.
>  
> Is it possible to do this with POI 3.5 version?
> 
> Thanks,
> Sakthi Priya
> 
> 
> 
>       
> 

-- 
View this message in context: 
http://www.nabble.com/Drop-down-list-in-excel-with-POI3.5-tp23215207p23239951.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to