我刚写的一段代码,供你参考吧。 Private Sub Cmd_import_Click() Dim cnExcel As New ADODB.Connection Dim rsExcel As New ADODB.RecordsetDim path As String CommonDialog1.Action = 1 path = CommonDialog1.FileName Set cnExcel = New ADODB.ConnectioncnExcel.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source='" + path + "';Extended Properties='Excel 8.0;HDR=Yes'" cnExcel.CursorLocation = adUseClient cnExcel.OpenSet rsExcel = New ADODB.Recordset If rsExcel.State = adStateOpen Then rsExcel.Close rsExcel.Open "select * from [sheet1$]", cnExcel, adOpenDynamic, adLockOptimistic Set Grid1.DataSource = rsExcelEnd Sub
Private Sub Cmd_import_Click()
Dim cnExcel As New ADODB.Connection
Dim rsExcel As New ADODB.RecordsetDim path As String
CommonDialog1.Action = 1
path = CommonDialog1.FileName
Set cnExcel = New ADODB.ConnectioncnExcel.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source='" + path + "';Extended Properties='Excel 8.0;HDR=Yes'"
cnExcel.CursorLocation = adUseClient
cnExcel.OpenSet rsExcel = New ADODB.Recordset
If rsExcel.State = adStateOpen Then rsExcel.Close
rsExcel.Open "select * from [sheet1$]", cnExcel, adOpenDynamic, adLockOptimistic
Set Grid1.DataSource = rsExcelEnd Sub