Read Excel data from Drop down into C# object array

前端 未结 1 1608
感动是毒
感动是毒 2021-01-27 04:20

From within C# I\'m trying to read data from an Excel sheet into an C# object.

Everything works fine except one small detail, Excel data from drop down lists.

S

相关标签:
1条回答
  • 2021-01-27 04:48

    The issue you're seeing occurs because the data for a dropdown isnt actually stored in the Range object itself. If you take a look at your WorkSheet object you'll notice a DropDowns method. This returns a DropDowns object which you can then call Item on to get an individual DropDown. From there you can work against the list within the DropDown itself like:

    (assuming: using Excel = Microsoft.Office.Interop.Excel)
    Excel.DropDowns allDropDowns = YourWorkSheet.DropDowns(Type.Missing);
    Excel.DropDown oneDropdown = allDropDowns.Item(YourIndex);
    

    I've not had a change to dig into getting the items out of the DropDown (only adding more with AddItem) however the Get List and Get Selected methods seem a good place to start.

    0 讨论(0)
提交回复
热议问题