ADO方式导入Excel数据获取表名
使用ADO方式导入excel数据时,获取excel工作表的名称,直接上示例代码(导入文件为XSL格式)#Define adschematables 20
#Define aduseclient 3
Local cxls,oconn,ors,tbnamestr
tbnamestr=""
m.cxls="c:\1.xls"
oconn = Createobject("adodb.connection") &&建立连接对象
With oconn
*连接字符串
.connectionstring = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' ;
+ m.cxls + ';Extended Properties="excel 8.0;HDR=YES;IMEX=1;";Persist Security Info=False'
.Open
Endwith
oconn.cursorlocation=aduseclient &&常数 3
ors=Createobject("adodb.recordset")
ors.cursorlocation= aduseclient
ors=oconn.openschema(adschematables) &&常烽 20
rsrow=ors.recordcount &&记录集的行
rscol=ors.Fields.Count &&记录集的列
Do While Not ors.Eof
For i=0 To rscol-1
If i=2
tstr=ors.Fields(i).Value
If Right(tstr,1)="$"
IF EMPTY(tbnamestr)
tbnamestr=tstr
ELSE
tbnamestr=tbnamestr+Chr(44)+tstr &&chr(44),逗号
ENDIF
Endif
Endif
Endfor
ors.movenext
ENDDO
?tbnamestr &&字符串内储存表名,以逗号分隔
ors.Close
oconn.Close