把Excel表当作数据表来读 strFileName = dirname & filename & ".xls" adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & strFileName & ";Extended Properties='Excel 8.0;HDR=Yes'" adoRecordset.Open "select * from [tow.sheet$] where 塔号 is not null", adoConnection, adOpenKeyset, adLockOptimistic有多少记录多少字段,循环就可以知道了
mysheet.usedrange.rows.countPrivate Function GetExcelRowCount(strSourceFile as string ,strSourceTable as string ) as Integer Dim cnSource As New ADODB.Connection Dim rsSource As New ADODB.Recordset cnSourceDb.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strSourceFile & ";Extended Properties=Excel 8.0;Persist Security Info=true" rsSource.CursorLocation = adUseClient rsSource.Open "select * from [" & strSourceTable & "]", cnSource, adOpenKeyset, adLockOptimistic GetExcelRowCount= rsSource.RecordCount cnSource.close rsSource.close set cnSource=nothing set rsSource=nothing End Function调用:GetExcelRowCount( "d:\new.xls","Sheet1$")
strFileName = dirname & filename & ".xls"
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & strFileName & ";Extended Properties='Excel 8.0;HDR=Yes'"
adoRecordset.Open "select * from [tow.sheet$] where 塔号 is not null", adoConnection, adOpenKeyset, adLockOptimistic有多少记录多少字段,循环就可以知道了
Dim cnSource As New ADODB.Connection
Dim rsSource As New ADODB.Recordset
cnSourceDb.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strSourceFile & ";Extended Properties=Excel 8.0;Persist Security Info=true"
rsSource.CursorLocation = adUseClient
rsSource.Open "select * from [" & strSourceTable & "]", cnSource, adOpenKeyset, adLockOptimistic
GetExcelRowCount= rsSource.RecordCount
cnSource.close
rsSource.close
set cnSource=nothing
set rsSource=nothing
End Function调用:GetExcelRowCount( "d:\new.xls","Sheet1$")
GetExcelColCount=rsSource.Fields.Count