如何实现EXCEL表数据导入到VB的DATAGRID控件中
展开全部
MsgBox "注意:请先将Excel表取名为333,然后将它放入E盘根目录下,否则不能导入数据", 48, "提示"
If Dir("e:\333.xls", vbDirectory) <> "" Then
FileCopy "e:\333.xls", "e:\444.xls"
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=e:\333.xls;Extended Properties='Excel 8.0;HDR=Yes'"
rs.Open "select * from [Sheet1$]", cn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs
Else:
MsgBox "没有找到E盘下名称为“" & 333 & "”Excel文件", 64, "系统提示"
End If
If Dir("e:\333.xls", vbDirectory) <> "" Then
FileCopy "e:\333.xls", "e:\444.xls"
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=e:\333.xls;Extended Properties='Excel 8.0;HDR=Yes'"
rs.Open "select * from [Sheet1$]", cn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs
Else:
MsgBox "没有找到E盘下名称为“" & 333 & "”Excel文件", 64, "系统提示"
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询