Bug 44773

Summary: Combo box in excel sheet
Product: POI Reporter: SUMIT <Sumit.Jain>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description SUMIT 2008-04-07 20:14:46 UTC
I want to create a combo-box or alist box in excel sheet. In what way, i can achieve this?
Comment 1 Josh Micich 2008-04-10 01:27:14 UTC
One way is through Excel 'Data Validations' (I am not sure if there are any better ways.)

Here is some quick code I hacked out of an existing test case:

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");

short rowIx = 0;
short colIx = 0;
HSSFDataValidation data_validation = new HSSFDataValidation(rowIx, colIx,rowIx, colIx);
data_validation.setDataValidationType(HSSFDataValidation.DATA_TYPE_LIST);
data_validation.setFirstFormula("$A$20:$A$29");
data_validation.setSecondFormula(null);
data_validation.setSurppressDropDownArrow(false);
data_validation.setShowPromptBox(false);
data_validation.setShowErrorBox(false);
sheet.addValidationData(data_validation);

for (int i=0; i<10; i++) {
   HSSFRow currRow = sheet.createRow(i+19);
   currRow.createCell((short)0).setCellValue(new HSSFRichTextString("val " + i));
}

File fOut = new File("c:/josh/temp/dfEx-out.xls");
try {
	FileOutputStream os = new FileOutputStream(fOut);
	wb.write(os);
	os.close();
} catch (IOException e) {
	throw new RuntimeException(e);
}


You probably want to do something a little different to this, but it should be a good start.  It would be helpful to know how to manipulate Data Validations manually through the Excel GUI.  That will make it easier to anticipate how things might be modeled in POI.