Free Support Forum - aspose.com

How to set a dynamic value to combo box component in java using aspose cells

Hi ,

Currently we are using licensed version of aspose-cells02.5.04,but as per requirement , i have to add combobox dynamically in x-cell report and value also need to be set while generationg report and should be editable after opening the xls report.

I got following code to add combobox in xls report but unable to set a value using setText method(i mean i am able to set but after opening the generated report if i will select any other value,then both values are becoming overlap due to this i am not able to see selected value with 100%clarity).

Please let me know how to set a value with out any issues.

Ex:

Workbook wb = new Workbook();

// Get the first worksheet.

Worksheet sheet1 = wb.getSheet(0);

Cells cells1 = sheet1.getCells();

com.aspose.cells.ComboBox comboBox = sheet1.getShapes().addComboBox(3, 5, 20, 0, 525, 15);

cells1.getCell("A1").setValue("One");

cells1.getCell("A2").setValue("Two");

cells1.getCell("A3").setValue("Three");

cells1.getCell("A4").setValue("Four");

cells1.getCell("A5").setValue("Five");

// comboBox.setLinkedCell(cells1.getCell("B1").getName());

comboBox.setInputRange("=Sheet1!A1:Sheet1!A5");

comboBox.setDropDownLines(5);

comboBox.setFilled(true);

comboBox.setText("Two");

// Saves the file.

wb.save("C:\\USERS\\Results\\outcombobox.xls");

Thanks&Regards

Sudhakar

Hi,

Thanks for your question and interest in Aspose.Cells for Java.

Please try ComboBox.setSelectedIndex(index) method to select the value of the combobox.