读书人

VB.net读取excel中某列信息其后提供

发布时间: 2013-07-08 14:13:00 作者: rapoo

VB.net读取excel中某列信息,然后提供给combobox
我最近在学习vb.net时遇到了一些问题,在这里向大家请教。谢谢!

我是想读取excel中某列的信息,该列可能会有行合并项。将此列中不同的文字获取出来输出给combobox。我是这样编程的:

Dim n As Integer = 1
Dim i as Integer=n-1
Dim comboboxstring(i) As String
Do While excelsheet.Cells(n, 3).value <> ""
comboboxstring(n - 2) = excelsheet.Cells(n, 2).value
n = n + 1
Loop
Me.ComboBox3.Items.Clear()
Me.ComboBox3.Items.AddRange(comboboxstring)

我的意思是当excel中,第三列某单元格不为空时,我就将其值赋予comboxstring()数组。最终将该数组添加到combobox的集合中。

现在我每次运行程序只能得到该列第一个单元格内容。下面的单元格不为空但没有加到combobox集合中,不知问题在哪里?

多谢!



[解决办法]
Dim n As Integer = 1
Dim comboboxstring() As String

Do While excelsheet.Cells(n, 3).value <> ""
Redim Preserve comboboxstring(n - 1)
comboboxstring(n - 1) = excelsheet.Cells(n, 2).value
n = n + 1
Loop
Me.ComboBox3.Items.Clear()
Me.ComboBox3.Items.AddRange(comboboxstring)

读书人网 >VB

热点推荐