主题:<求助>VB2005怎样从EXCEL数组中导入数据到文本框
在导入数据的时候出现问题,请各位大侠帮忙解决下
最好能有个导入的源代码
我的邮箱:qyx86312@163.com
QQ:164394398
不胜感激!
源代码有如下[size=6][size=5],[color=FF0000]提示错误“从类型“Range”到类型“String”的转换无效”[/color][/size][/size] '
'将Excel中的数据导入到文本框中
'
Private Sub Menu_LoadData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_LoadData.Click
Dim x1App As Excel.Application
Dim x1Book As Excel.Workbook
Dim x1Sheet As Excel.Worksheet
Dim FileName As String
Dim i As Integer
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Excel表|*.xls"
OpenFileDialog1.ShowDialog()
FileName = OpenFileDialog1.FileName
If FileName = "" Then
Exit Sub
End If
x1App = CreateObject("Excel.Application")
x1Book = x1App.Workbooks.Add
x1Sheet = x1Book.Worksheets(1) '打开Excel工作表
x1Sheet.Activate() '激活工作表
Me.n.Text = x1Sheet.Cells(i, 2)
Me.k.Text = x1Sheet.Cells(i, 2)
Me.x0.Text = x1Sheet.Cells(i, 2)
Me.α0.Text = x1Sheet.Cells(i, 2)
Me.F0.Text = x1Sheet.Cells(i, 2)
Me.Mv.Text = x1Sheet.Cells(i, 2)
Me.Ms.Text = x1Sheet.Cells(i, 2)
Me.Mre.Text = x1Sheet.Cells(i, 2)
Me.Jr.Text = x1Sheet.Cells(i, 2)
Me.l.Text = x1Sheet.Cells(i, 2)
Me.Mt.Text = x1Sheet.Cells(i, 2)
Me.Mp.Text = x1Sheet.Cells(i, 2)
Me.K1.Text = x1Sheet.Cells(i, 2)
Me.K2.Text = x1Sheet.Cells(i, 2)
Me.C1.Text = x1Sheet.Cells(i, 2)
Me.C2.Text = x1Sheet.Cells(i, 2)
x1Book.RunAutoMacros(Excel.XlRunAutoMacro.xlAutoClose) '执行Excel关闭宏
x1Book.Close(True) '关闭Excel工作簿
x1App.Quit() '关闭Excel
x1App = Nothing
End Sub
[img]C:\Users\sealigh\1.jpg[/img]
最好能有个导入的源代码
我的邮箱:qyx86312@163.com
QQ:164394398
不胜感激!
源代码有如下[size=6][size=5],[color=FF0000]提示错误“从类型“Range”到类型“String”的转换无效”[/color][/size][/size] '
'将Excel中的数据导入到文本框中
'
Private Sub Menu_LoadData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_LoadData.Click
Dim x1App As Excel.Application
Dim x1Book As Excel.Workbook
Dim x1Sheet As Excel.Worksheet
Dim FileName As String
Dim i As Integer
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Excel表|*.xls"
OpenFileDialog1.ShowDialog()
FileName = OpenFileDialog1.FileName
If FileName = "" Then
Exit Sub
End If
x1App = CreateObject("Excel.Application")
x1Book = x1App.Workbooks.Add
x1Sheet = x1Book.Worksheets(1) '打开Excel工作表
x1Sheet.Activate() '激活工作表
Me.n.Text = x1Sheet.Cells(i, 2)
Me.k.Text = x1Sheet.Cells(i, 2)
Me.x0.Text = x1Sheet.Cells(i, 2)
Me.α0.Text = x1Sheet.Cells(i, 2)
Me.F0.Text = x1Sheet.Cells(i, 2)
Me.Mv.Text = x1Sheet.Cells(i, 2)
Me.Ms.Text = x1Sheet.Cells(i, 2)
Me.Mre.Text = x1Sheet.Cells(i, 2)
Me.Jr.Text = x1Sheet.Cells(i, 2)
Me.l.Text = x1Sheet.Cells(i, 2)
Me.Mt.Text = x1Sheet.Cells(i, 2)
Me.Mp.Text = x1Sheet.Cells(i, 2)
Me.K1.Text = x1Sheet.Cells(i, 2)
Me.K2.Text = x1Sheet.Cells(i, 2)
Me.C1.Text = x1Sheet.Cells(i, 2)
Me.C2.Text = x1Sheet.Cells(i, 2)
x1Book.RunAutoMacros(Excel.XlRunAutoMacro.xlAutoClose) '执行Excel关闭宏
x1Book.Close(True) '关闭Excel工作簿
x1App.Quit() '关闭Excel
x1App = Nothing
End Sub
[img]C:\Users\sealigh\1.jpg[/img]