Bug 44773 - Combo box in excel sheet
Summary: Combo box in excel sheet
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-07 20:14 UTC by SUMIT
Modified: 2008-04-10 01:27 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.