How to add dropdown in Aspose.Cells


Hi,

I have a requirement like

I have to create Excel file using Aspose.Cell, in that excel file first row will be column headings and 2nd row onwards corresponding values of the column.

Suppose If the column will be “Country”, then I want to display dropdown for that and values of dropdown get filled from the Database.

Please suggest me how to done this. This is very urgent for me.

Thanks,
Veeru1.

Hi,

Well, I think you may use either use data validations (List validation) or simply add ComboBox control to the cells for your requirements, for reference, see the documents:

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/data-filtering-and-validation.html

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/working-with-controls.html

In both approaches (mentioned above), you need to specify the source range for the dropdown. Currently, you cannot specify the source range for data validation or ComboBox control directly from database. Once workaround is, you can import the data to fill your worksheet cells (you may add a new sheet and fill the data from the source database table and set the worksheet hidden for the users), now you can specify the source range for your drop downs.

Thank you.


Hi,

Thanks for your reply.

Already I have a Excel file, which it contains drop downs in the cells for some columns like Country , State etc.

While reading the above Excel file, I want to access those dropdown controls and get filled from the database using Aspose.Cells.

Please suggest me that how to done this or any code sample.

Thanks,
Veeru1.

Hi,

Well, as I said, you cannot set source range directly from database table. You can import the data from database table using Cells.ImportDataTable() method to some worksheet cells, see the document : http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/importing-data-to-worksheets.html how you can import data from different data sources. You may get the existing comobox shapes in the sheet, see the sample code segment:

e.g

Aspose.Cells.Drawing.Shape shapeByName = worksheet.Shapes[0];;
Aspose.Cells.Drawing.ComboBox comboShape = (Aspose.Cells.Drawing.ComboBox)shapeByName;
if (comboShape != null)
{
comboShape.SelectedIndex = 1;


string SelectedValue = comboShape.SelectedValue.ToString();

string val = comboShape.LinkedCell.Replace(“$”, string.Empty);

}

Thank you.