We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Combo box in Excel

Hi Aspose support team,

My requirement is like this, i have an combo box in the excel sheet, i need to populate the value to the particular combo box. and i need to assign the calculated cell value based the on the combo box selected value changed.

Could you please help me how to achieve this functionality? Please provide the sample piece of code, if you have.

Thanks
Saravanan K

Hi,

Thanks for your posting and considering Aspose.Cells for .NET.

Please see the following sample code. It illustrates how to use Aspose.Cells to add a combo box control inside the Excel file.

For adding different sorts of controls e.g textbox, combobox, radiobutton etc in the Excel file using Aspose.Cells, please refer to this article.

  1. Managing Controls

C#

//Create a new Workbook.

Workbook workbook = new 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(“Employee:”);


//Set it bold.

cells[“B3”].Style.Font.IsBold = true;


//Input some values that denote the input range

//for the combo box.

cells[“A2”].PutValue(“Emp001”);

cells[“A3”].PutValue(“Emp002”);

cells[“A4”].PutValue(“Emp003”);

cells[“A5”].PutValue(“Emp004”);

cells[“A6”].PutValue(“Emp005”);

cells[“A7”].PutValue(“Emp006”);


//Add a new combo box.

Aspose.Cells.Drawing.ComboBox comboBox = sheet.Shapes.AddComboBox(2, 0, 2, 0, 22, 100);


//Set the linked cell;

comboBox.LinkedCell = “A1”;


//Set the input range.

comboBox.InputRange = “A2:A7”;


//Set no. of list lines displayed in the combo

//box’s list portion.

comboBox.DropDownLines = 5;


//Set the combo box with 3-D shading.

comboBox.Shadow = true;


//AutoFit Columns

sheet.AutoFitColumns();


//Saves the file.

workbook.Save(@“d:\test\tstcombobox.xls”);