It's raining today confing me to the workshop and office. Anyway, that means
I have some time to play and I found something more about the
HSSFDataValidation class today.

There is no need to set up a named range to create a drop down list and to
set up input validation on a cell. There are two other options.

The first is to enter the values into a contiguous range of cells on a
worksheet and then reference that range bay passing an appropriate value to
the setFirstFormula() method of the HSSFDataValidation object. The second is
to create a comma spearated list of values enclosed withiom double quotes
and to pass this to the setFirstFormula() method of the HSSFDataValidation
object. This code snippet shows both - I have commented out the lines of
code and shown only the latter method.

// New Workbook.
outputFile = new File("C:/temp/ddlist book.xls");
fos = new FileOutputStream(outputFile);
workbook = new HSSFWorkbook();
// Add a sheet
sheet = workbook.createSheet("List Sheet");
// Either of these two lines will supply the list of values for the drop
down
// There is no need to create a named range and reference that and there is
// no need either to include the list's values on the Worksheet, a comma
// separated list can be provided as shown below.
//String strFormula = "$A$1:$A$4";
//String strFormula = "\"100, 200, 300, 400, 500\"";
// Just for the sake of a demo, am using the comma separated list
// of value firstly.
String strFormula = "\"100, 200, 300, 400, 500\"";
dataValidation = new
HSSFDataValidation((short)(start_row),(short)1,(short)(start_row),(short)1);
dataValidation.setDataValidationType(HSSFDataValidation.DATA_TYPE_LIST);
dataValidation.setFirstFormula(strFormula);
dataValidation.setSecondFormula(null);
dataValidation.setExplicitListFormula(true);
dataValidation.setSurppressDropDownArrow(false);
dataValidation.setEmptyCellAllowed(true);
dataValidation.setShowPromptBox(false);
dataValidation.createErrorBox("Invalid input !", "Something is wrong. check
condition!");
sheet.addValidationData(dataValidation);
// Write the workbook away.
workbook.write(fos);

Still though I cannot find a way to use values from cells on another
worksheet!!! Maybe though that does not matter here.


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-tp23215207p23254021.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