Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JSpreadsheet
>
Tutorial
> Insert Combo Box
The following example shows you how to insert a Combo Box.
import com.independentsoft.office.spreadsheet.Cell; import com.independentsoft.office.spreadsheet.Workbook; import com.independentsoft.office.spreadsheet.Worksheet; import com.independentsoft.office.vml.Anchor; import com.independentsoft.office.vml.ClientData; import com.independentsoft.office.vml.DropdownStyle; import com.independentsoft.office.vml.ObjectType; import com.independentsoft.office.vml.Position; import com.independentsoft.office.vml.SelectionType; import com.independentsoft.office.vml.Shape; import com.independentsoft.office.vml.ShapeStyle; public class Example { public static void main(String[] args) { try { Workbook book = new Workbook(); Worksheet sheet1 = new Worksheet(); sheet1.set("A1", new Cell("Value1")); sheet1.set("A2", new Cell("Value2")); sheet1.set("A3", new Cell("Value3")); sheet1.set("A4", new Cell("Value4")); sheet1.set("A5", new Cell("Value5")); ShapeStyle shapeStyle = new ShapeStyle(); shapeStyle.setPosition(Position.ABSOLUTE); shapeStyle.setLeftMargin("96pt"); shapeStyle.setTopMargin("30pt"); shapeStyle.setWidth("96pt"); shapeStyle.setHeight("15pt"); ClientData comboBox = new ClientData(); comboBox.setObjectType(ObjectType.DROPDOWN_BOX); comboBox.setSizeWithCells(true); comboBox.setListItemsSourceRange("$A$1:$A$5"); comboBox.setSelectedEntry(0); comboBox.setSelectionType(SelectionType.SINGLE); comboBox.setDropdownStyle(DropdownStyle.COMBO); comboBox.setDropdownMaximumLines(8); Anchor anchor = new Anchor(); anchor.setLeftColumn(2); anchor.setLeftOffset(1); anchor.setTopRow(0); anchor.setTopOffset(1); anchor.setRightColumn(3); anchor.setRightOffset(63); anchor.setBottomRow(1); anchor.setBottomOffset(1); comboBox.setAnchor(anchor); Shape shape = new Shape(shapeStyle); shape.getContent().add(comboBox); sheet1.getVmlObjects().add(shape); book.getSheets().add(sheet1); book.save("c:\\test\\output.xlsx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*