0

In my application I have a requirement to create an excel file contains several combos.I have created upto that. enter image description here

Now I have to read those combo's value from excel. I have found a link to read from excel Read From Excel

But In my code I have found this..

enter image description here

enter image description here

Here is my code

Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook oWB;
Microsoft.Office.Interop.Excel._Worksheet oSheet;
Microsoft.Office.Interop.Excel.Range oRng;

//Get a new workbook.
oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Open("C:\\TopicUpload_2017October14.xls"));
//3rd Sheet
oSheet = (Microsoft.Office.Interop.Excel._Worksheet) oWB.Sheets.get_Item(1);

 Microsoft.Office.Interop.Excel.DropDowns allDropDowns = oSheet.DropDowns(Type.Missing);
 Microsoft.Office.Interop.Excel.DropDown oneDropdown = allDropDowns.Item("2");

Now how can I get selected text of this dropdown.. When I inspect I got

oneDropdown.ListCount = 5.0; // items count of second drop down, which is true

But could not able to get selected text.

oneDropdown.Text
Babai
  • 99
  • 1
  • 14

1 Answers1

0

After searching , I'm able to get it.

#region Read value from excel combobox
                    Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
                    Microsoft.Office.Interop.Excel._Workbook oWB;
                    Microsoft.Office.Interop.Excel._Worksheet oSheet;
                    Microsoft.Office.Interop.Excel.Range oRng;

                    //Get a new workbook.
                    oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Open("C:\\TopicUpload_2017October14.xls"));
                    //3rd Sheet
                    oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.Sheets.get_Item(1);

                    Microsoft.Office.Interop.Excel.DropDowns allDropDowns = oSheet.DropDowns(Type.Missing);
                    Microsoft.Office.Interop.Excel.DropDown oneDropdown = allDropDowns.Item("1"); // first combo
                    string selectedText = oneDropdown.get_List(oneDropdown.ListIndex); 
    #endregion
Babai
  • 99
  • 1
  • 14