无法将 'System.__ComObject' 类型的 COM 对象转换为 class 类型 'System.Array'

Unable to cast COM object of type 'System.__ComObject' to class type 'System.Array'

我尝试使用 VB.net 读取 excel 字符,我使用 VS2013 和 Office2013

当我使用 LBOUND 和 UBOUND 函数时,它导致了这个异常

代码是:

 Dim objApp As New Excel.Application
 Dim objWorkbook As Excel.Workbook
 Dim objWorksheet As Excel.Worksheet

 objWorkbook = objApp.Workbooks.Open(path & FileName)
 objWorksheet = objWorkbook.Sheets(2)
 area = objWorkSheet.Range("a7", "a8")
 Debug.Print(LBound(area))

例外情况:

未处理System.InvalidCastException HResult=-2147467262
Message=无法将类型为“System.__ComObject”的 COM 对象强制转换为类类型“System.Array”。表示 COM 组件的类型实例不能强制转换为不表示 COM 组件的类型;不过,只要基础 COM 组件支持对接口 IID 的 QueryInterface 调用,就能将这些实例强制转换为接口。

我搜索了 google 没有太多有用的信息,因此非常感谢您的帮助。

Range property returns a Range object. To get the value, use the Value or Value2 property of the Range object. The value will be a 2D-array (matrix) when the Range object spans more than one cell. If the Range object 仅跨越单个单元格,该值将是一个标量。

Debug.Print(LBound(area.Value))