从“Object(,)”类型到“String”类型的转换无效

从“Object(,)”类型到“String”类型的转换无效

问题描述:

我正在使用VB.Net代码处理/阅读Excel工作簿。

如果工作表少于20000行,一切正常,但如果超过20000则会抛出异常。



I am handling/reading Excel workbook using VB.Net Code.
Everything goes OK if worksheet has less than 20000 rows, but if it is more than 20000 then it throws following exception.

InvalidCastException Occured
Conversion from type 'Object(,)' to type 'String' is not valid.





我的问题是它为什么有效,而其他时间没有?

可能是什么潜在问题?



代码如下:





My problem is that why it works some time and does not other time?
What could be the potential problem??

Code looks like this:

uArea.Digits = CurrentRow.Columns(AREA_DIGIT).value 
uArea.ValidFrom = CurrentRow.Columns(VALID_FROM).value





编辑:这可能吗是我需要暴露或处置excel对象的原因?在这种情况下,是否可以处置Excel对象?或者我可以使用GC.Collect吗?请帮忙。



Could this be the reason that i need to expose or dispose excel object ? in that case , is it possible to dispose Excel object? OR can i use GC.Collect? Please Help.

这个错误实际上可能与excel的大小无关。在行20000之后的行之一可以具有可以是不同类型的一些数据。值得对Excel文件进​​行快速数据验证。
This error may actually have nothing to do with the size of the excel. One of the rows after row 20000 may have some data that may be of a different type. It will be worth doing a quick data validation of the Excel file.