|
已知:一个Excel工作簿的Sheet1表是空的,并且通过手动删除全表所有单元格。
目的:想通过SQL语句来判断其Sheet1表是否为空?
SQL语句:Select Count(*) From Table
代码:
- Option Explicit
- Sub Test()
- Dim sData$, I&, iT&
- Dim Cnn As Object, Str_Cnn$, qSQL$
- Set Cnn = CreateObject("Adodb.Connection")
- Select Case Application.Version * 1
- Case Is <= 11
- Str_Cnn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties='Excel 8.0;HDR=NO;IMEX=1';Data source="
- Case Is >= 12
- Str_Cnn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=NO;IMEX=1';Data source="
- End Select
- sData = ThisWorkbook.FullName
- Cnn.Open Str_Cnn & sData
- qSQL = "SELECT COUNT(*) FROM [Sheet1$]"
- iT = Cnn.Execute(qSQL).getrows()(0, 0)
- Debug.Print sData, iT
- End Sub
复制代码 执行结果显示:H:\空表(无表头更无记录).xls 1
疑问:明明没有任何内容,为什么显示的结果却是1呢?
|
|