VB.Net从Excel中拖动date到arrays

我一直有很多麻烦从Excel中拉date和加载到一个数组。 我有代码,应该为所有意图和目的工作,但没有被加载到数组中。 当我在数组中search一个值时,不pipe它是什么,它都会在数组中的索引-1处find它。 代码如下。

Dim d As String Dim strDate(0 To 35) As String Dim dCell As Object Dim tDate As String = Now.ToShortDateString Dim dCount = WFMBook.Range("G2:AO2").Cells.Count For y = 1 To dCount Step +1 For Each dCell In WFMBook.Range("G2:AO2").Cells(y).Value.ToString d = WFMBook.Range("G2:AO2").Cells.Value.ToString Next strDate(y) = d TextBox1.Text = strDate(0) Next 

然后,所有的数据据说加载到数组(我有文本框function,以检查是否在数组中 – 没有结果被打印到文本框中)。我执行此function:

 Dim dindex As Integer = Array.FindIndex(strDate, Function(s2) s2 = tDate) MsgBox("Found Date " & tDate & " at index " & dindex) 

正如我前面所说,虽然,MsgBox显示它在索引-1处find,并且没有数组结果被打印到文本框。 我相信这与Exceldate/时间有点关系。 我怎么能得到这个正确的加载date到一个string格式前“12/3/2015”到数组? 谢谢!

看来你的问题是你没有正确地遍历你的范围。 您只需要引用与您的WFMBook.Range("G2:AO2")testing范围相对应的Cells属性。

 Dim checkRange = WFMBook.Range("G2:AO2") Dim dCount = checkRange.Cells.Count For y = 1 To dCount ' Row postion (1) remains the same, but the column is incremented with y. d = checkRange.Cells(1, y).Value.ToString strDate(y) = d TextBox1.Text = strDate(0) Next