如何使用C#Excel Interop读取excel列表元素(数据validation)?

我有一个Excel文件,其中的“数据validation”设置为“列表”的单元格。 由此,这个单元格是一个下拉列表。 如何使用C#Excel Interop读取此列表的元素? 我可以轻松读取当前选定的值:

Range range = xlWorkSheet.UsedRange; // Worksheet string cellValue = (range.Cells[x, y] as Excel.Range).Value2.ToString(); 

但我无法读取此单元格包含的下拉列表的内容。

正如它在这里陈述我怎样读取从c#或vb.net的Excel下拉列表或checkbox的值? 有没有简单的方法来做到这一点,但是可以创build自定义函数并手动执行。 下面是我的function,读取下拉值到一个string列表。 这个函数是基于前面提到的一个问题,但我在其他工作表上增加了对公式的支持。

 List<string> ReadDropDownValues(Excel.Workbook xlWorkBook, Excel.Range dropDownCell) { List<string> result = new List<string>(); string formulaRange = dropDownCell.Validation.Formula1; string[] formulaRangeWorkSheetAndCells = formulaRange.Substring(1, formulaRange.Length - 1).Split('!'); string[] splitFormulaRange = formulaRangeWorkSheetAndCells[1].Split(':'); Excel.Worksheet xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(formulaRangeWorkSheetAndCells[0]); Excel.Range valRange = (Excel.Range)xlWorkSheet.get_Range(splitFormulaRange[0], splitFormulaRange[1]); for (int nRows = 1; nRows <= valRange.Rows.Count; nRows++) { for (int nCols = 1; nCols <= valRange.Columns.Count; nCols++) { Excel.Range aCell = (Excel.Range)valRange.Cells[nRows, nCols]; if (aCell.Value2 != null) { result.Add(aCell.Value2.ToString()); } } } return result; }