Free Support Forum - aspose.com

ListBox

Hi,

there is a class called ‘ListBox’, but with no constructor. Is it possible to create ListBoxes with Aspose.Cells (4.3.0)? Thanks in advance.

Regards
Zijad

Hi Zijad,

Yes, quite possible, please consult the following code snippet:

//Create a new Workbook.
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Get the worksheet cells collection.
Cells cells = sheet.Cells;
//Input a value.
cells["B3"].PutValue("Choose Dept:");
//Set it bold.
cells["B3"].Style.Font.IsBold = true;
//Input some values that denotes the input range
//for the list box.
cells["A2"].PutValue("Sales");
cells["A3"].PutValue("Finance");
cells["A4"].PutValue("MIS");
cells["A5"].PutValue("R&D");
cells["A6"].PutValue("Marketing");
cells["A7"].PutValue("HRA");
cells["A8"].PutValue("A");
cells["A9"].PutValue("B");
cells["A10"].PutValue("C");
cells["A11"].PutValue("D");
cells["A12"].PutValue("E");
cells["A13"].PutValue("F");
//Add a new list box.
Aspose.Cells.ListBox listBox = sheet.Shapes.AddListBox(2, 0, 3,0,70, 100);
//Set the placement type.
listBox.Placement = PlacementType.FreeFloating;
//Set the linked cell.
listBox.LinkedCell = "A1";
//Set the input range.
listBox.InputRange = "A2:A13";
//Set the slection tyle.
listBox.SelectionType = SelectionType.Multi;
//Set the list box with 3-D shading.
listBox.Shadow = true;



//Saves the file.
workbook.Save(@"d:\test\testListBox.xls");

For further reference, please check how to create different controls / drawing objects using Aspose.Cells APIs: http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/working-with-controls.html

Thank you.