一连接的创建:
Public Sub OpenXLSConn(strFile As String)
Const ProcName = "OpenXLSConn"
On Error GoTo ErrHandler
Dim strConn As String
1 strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
2 Set objXLSConn = New ADODB.Connection
3 objXLSConn.Open strConn
Exit Sub
ErrHandler:
ErrLog Erl,Err.Number,Err.Description,ProcName,True,True
End Sub
二 内容的读取:
CommonDialog1.ShowOpen strFilePath = CommonDialog1.FileName 7 strPKLineData = "" 8 strFillLine = "" 9 Set objXLSRS = New ADODB.Recordset '10 CreatesqlConn 11 OpenXLSConn strFilePath 12 strXLSsql = "Select * From [Items$]" 13 objXLSRS.CursorLocation = adUseClient 14 objXLSRS.Open strXLSsql,objXLSConn,adOpenStatic 16 While Not objXLSRS.EOF 50 For j = 0 To 30 51 strArray(j) = NullToValue(objXLSRS(j),"") 52 strFillLine = strFillLine & strArray(j) & "|" 53 Next j 72 objXLSRS.MoveNext 73 Wend 87 Set objXLSRS = Nothing 88 CloseXLSConn
原文链接:https://www.f2er.com/vb/258402.html