如何将一个excel导入到我的datagrid中呢
注意:不是将datagrid导入到excel要代码,跪求! --------------------编程问答-------------------- Private Sub mnuImport_Click()
Dim strSource As String
Dim Cn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
comOpen.Filter = "报表文件(*.xls)|*.xls"
comOpen.ShowOpen
If comOpen.FileName = "" Then
Exit Sub
Else
strSource = comOpen.FileName
strSource=inputbox$()
If strSource <> "" Then
If strSource = "" Then
MsgBox "请确定名字", vbInformation, "提示"
Exit Sub
ElseIf strSource = "sheet1" Or strSource = "sheet3" Then
If Cn.State <> 1 Then
Cn.CursorLocation = adUseClient
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;" _
& "Data Source=" & strSource & ";Extended Properties='Excel 8.0;HDR=Yes'"
Rs.Open "select * from [" & strSource & "$]", Cn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = Rs
DataGridColumnWidth
MsgBox "文件导入成功", vbInformation, "提示"
DataGrid1.Visible = True
ElseIf Cn.State = 1 Then
MsgBox "已经有一个连接", vbCritical, "警告"
Exit Sub
End If
Else
MsgBox "名字错误", vbInformation, "提示"
Exit Sub
End If
Else
Exit Sub
End If
strSource = ""
End If
End Sub --------------------编程问答-------------------- 用EXCEL做数据库对象,产生记录集,然后设定DATAGRID的数据源就可以了。。 --------------------编程问答-------------------- 查询数据库,把记录一条一条向表格里面填写就是了。
补充:VB , 数据库(包含打印,安装,报表)