2
votes

How to read Excel ListBox value in Java using Apache POI ? On web this is the only thread that discussed abou this problem. http://apache-poi.1045710.n5.nabble.com/sample-code-to-read-excel-listbox-values-td2308018.html

But this code does not work. It uses this code

    HSSFWorkbook workbook = null;
    HSSFSheet sheet = null;
    HSSFRow row = null;
    HSSFCell cell = null;
    HSSFDataValidation dataValidation = null;

    try { 
        inputStream = new java.io.FileInputStream(new java.io.File("C:/temp/data validation.xls"));
        workbook = new HSSFWorkbook(inputStream);
        sheet = workbook.getSheetAt(0);
        validationRecords = sheet.getDVRecords(); 

But in HSSF version which I am using "getDVRecords" method is not available in HSSFSheet.

Is there any better and working code ?

EDIT: I already have code to read values of normal cell or dropdown. I am specifically looking for code to read listbox. List box is where you can select more than one values. ListBox are not tied to any specific cell. They appear as components overlaid on the sheet

Please refer this link to see how to add listbox. This will help better understand my question. http://office.microsoft.com/en-in/excel-help/add-a-list-box-or-combo-box-to-a-worksheet-HP010236681.aspx

1
Are you perhaps using an old version of Apache POI? Make sure you've upgraded to the latest one (3.10) and try againGagravarr
@Gagravarr I am using poi-3.10-FINAL.jar Still "getDVRecords" method is not available in HSSFSheet.Kaushik Lele

1 Answers

0
votes

ever tried to use the jExcel API? It uses Apache POI and is really easy to handle:

net.sourceforge.jexcelapi:jxl:2.6.12

you can try it somehow like this:

WorkSheet sheet;

Cell comboBox = sheet.getCell(x,y);
String value= comboBox.getContents();

greetings