// Create a new workbook Workbook workbook = new Workbook(); IWorksheet ws = workbook.getWorksheets().get("Sheet1"); ws.getRange("A:A").setColumnWidthInPixel(28d); // No data binding ws.getRange("B2").setValue("List boxes support unbound mode. You can add items with code."); IListBox listBox1 = ws.getControls().addListBox(23.6, 32.8, 170, 80.9); listBox1.getItems().add(new ListBoxItem("Unbound Item 1")); listBox1.getItems().add(new ListBoxItem("Unbound Item 2")); listBox1.getItems().add(new ListBoxItem("Unbound Item 3")); listBox1.setSelectedIndex(0); // Items source binding ws.getRange("B10").setValue("You can also use data binding to set the item source and bind selected index."); ws.getRange("F11:F14").setValue(new Object[][] { { "Items"}, { "Item 1"}, { "Item 2"}, { "Item 3"} }); ws.getRange("G11:G12").setValue(new Object[][] { { "Value"}, { 1d} }); IListBox listBox2 = ws.getControls().addListBox(23.7, 153.7, 170, 80.30); listBox2.setItemsSourceRange(ws.getRange("F12:F14")); listBox2.setLinkedCell(ws.getRange("G12")); listBox2.setSelectedIndex(0); // Multi-select ws.getRange("B18").setValue("You can select multiple items if you change the selection mode."); IListBox listBox3 = ws.getControls().addListBox(24.1, 273.1, 170, 78.69); listBox3.getItems().add(new ListBoxItem("Multi-select Item 1")); listBox3.getItems().add(new ListBoxItem("Multi-select Item 2")); listBox3.getItems().add(new ListBoxItem("Multi-select Item 3")); listBox3.setSelectionMode(SelectionMode.Extended); listBox3.getSelectedItems().add(listBox3.getItems().get(0)); listBox3.getSelectedItems().add(listBox3.getItems().get(2)); // Save to an excel file workbook.save("ListBoxesBasicUsage.xlsx");
// Create a new workbook var workbook = Workbook() val ws = workbook.worksheets["Sheet1"] ws.getRange("A:A").columnWidthInPixel = 28.0 // No data binding ws.getRange("B2").value = "List boxes support unbound mode. You can add items with code." val listBox1 = ws.controls.addListBox(23.6, 32.8, 170.0, 80.9) listBox1.items.add(ListBoxItem("Unbound Item 1")) listBox1.items.add(ListBoxItem("Unbound Item 2")) listBox1.items.add(ListBoxItem("Unbound Item 3")) listBox1.selectedIndex = 0 // Items source binding ws.getRange("B10").value = "You can also use data binding to set the item source and bind selected index." ws.getRange("F11:F14").value = arrayOf(arrayOf("Items"), arrayOf("Item 1"), arrayOf("Item 2"), arrayOf("Item 3")) ws.getRange("G11:G12").value = arrayOf(arrayOf("Value"), arrayOf(1.0)) val listBox2 = ws.controls.addListBox(23.7, 153.7, 170.0, 80.30) listBox2.itemsSourceRange = ws.getRange("F12:F14") listBox2.linkedCell = ws.getRange("G12") listBox2.selectedIndex = 0 // Multi-select ws.getRange("B18").value = "You can select multiple items if you change the selection mode." val listBox3 = ws.controls.addListBox(24.1, 273.1, 170.0, 78.69) listBox3.items.add(ListBoxItem("Multi-select Item 1")) listBox3.items.add(ListBoxItem("Multi-select Item 2")) listBox3.items.add(ListBoxItem("Multi-select Item 3")) listBox3.selectionMode = SelectionMode.Extended listBox3.selectedItems.add(listBox3.items[0]) listBox3.selectedItems.add(listBox3.items[2]) // Save to an excel file workbook.save("ListBoxesBasicUsage.xlsx")