Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Usually the items are binded to the Excel ComboBox by specifying the range of the cells. The values present in the particular range of cells are listed as ComboBox items in Excel files. Also, Essential XlsIO returns the proper range even through the referenced/binded cells are in different worksheet. The property "xlComboBox.ListFillRange" holds the range of the cells which are referenced/binded for populating the combobox items. Using this property, you can retrieve the range and then iterate through the range to get all the combobox items. Herewith i have attached the code snippet to retrieve the ComboBox items.</p> <pre><code> private void button1_Click(object sender, EventArgs e) { //Instantiate the spreadsheet creation engine. ExcelEngine excelEngine = new ExcelEngine(); //Instantiate the excel application object. IApplication application = excelEngine.Excel; //Open the excel file and instantiate the workbook object IWorkbook workbook = application.Workbooks.Open(@"..\..\Data\Book1.xlsx"); //Retrieve the Excel comboBox from the worksheet IComboBoxShape xlComboBox = workbook.Worksheets[0].ComboBoxes[0]; //user defined method to retrieve Excel ComboBox items and populate them in a Windows forms - ComboBox control RetrieveItemsFromExcelComboBox(xlComboBox, comboBox1); xlComboBox = workbook.Worksheets[0].ComboBoxes[1]; RetrieveItemsFromExcelComboBox(xlComboBox, comboBox2); //Close the workbook. workbook.Close(); //Dispose the excel engine excelEngine.Dispose(); } /// &lt;summary&gt; /// Retrieve the items from the Excel ComboBox and populate them in Windows form - ComboBox control /// &lt;/summary&gt; /// &lt;param name="xlComboBox"&gt;Excel combobox instance (IComboBoxShape)&lt;/param&gt; /// &lt;param name="comboBox"&gt;Windows Forms - Combo Box instance&lt;/param&gt; private void RetrieveItemsFromExcelComboBox(IComboBoxShape xlComboBox, ComboBox wfComboBox) { //Get the range where the ComboBox items are present in the workbook IRange xlRange = xlComboBox.ListFillRange; //iterate through the range of the comboBox items and add them into the Windows forms - ComboBox control for (int rowIndex = xlRange.Row; rowIndex &lt;= xlRange.LastRow; rowIndex++) { for (int colIndex = xlRange.Column; colIndex &lt;= xlRange.LastColumn; colIndex++) { wfComboBox.Items.Add(xlRange[rowIndex, colIndex].DisplayText); } } wfComboBox.SelectedIndex = xlComboBox.SelectedIndex - 1; } </code></pre> <p>Let me know if it helps you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload