阅微草人的测试工作,伴随着初入社会的无奈艰辛彷徨,但是这些都会过去的,已经找到了自己的方向,正在努力中。学习像路飞那样的勇敢、自信、无畏、前进,真诚的伙伴。

ado读取excel文件中数据的2种方式

上一篇 / 下一篇  2007-06-01 11:21:30 / 个人分类:QTP

'ado读取excel文件中数据的2种方式
X!fK8P/B2Sg2bL;B0
}4Q;YG3Z V0Dim cnn,rst,strnn
[8`'H.zS3y0strnn="Provider=MSDASQL.1;Persist Security Info=False;Data Source=ExcelFiles;"51Testing软件测试网e` U#I*wR
strnn=strnn & "Initial Catalog=c:\REDB00000811.xls"
#zo _9q3?^V0set cnn=createobject("ADODB.connection")51Testing软件测试网#T![M2u?cc+C2jE
set rst=createobject("ADODB.recordset")51Testing软件测试网 A3j/D^,`
cnn.open strnn
!G([ R5kh0'使用表名跟美元符号51Testing软件测试网 VFcPD,x8{
rst.open "select * from [sheet1$]",cnn,1,1
U|7Uw5a0rst.movefirst
f$u0j4jy~&~2H\0tmp0=rst.fields(0)51Testing软件测试网LVBr+H3U
tmp1=rst.fields(1)
%h$N @ Cj c0tmp2=rst.fields(2)
w} d y$i!}0tmp3=rst.fields(3)51Testing软件测试网Sv3]!S{)sP
tmp4=rst.fields(4)
%Mq:]J3QyE/d.p0tmp5=rst.fields(5)
YY^+BJ2O0rst.movenext51Testing软件测试网 TS(u(QXQ
tmp6=rst.fields(0)51Testing软件测试网*f(qZY%CTIK
rst.close51Testing软件测试网"q'HnY f
'与特定地址 (为示例, $ Sheet 1 [ A1:B10 ]) 指定区域。51Testing软件测试网!Ov C^m|P.I`w
rst.open "select * from [sheet1$A3:E5]",cnn '其实,数据是A4到E5的数据。A3所在的一行数据不                                             '取。
:HPj'J m0TP%B+q!wJ-br0rst.movefirst
/P1qA'j8r\2MC,v0tmp7=rst.fields(0)51Testing软件测试网\$|$?;r4q3z\#H m6K
rst.movenext
'M Dp*f4it0tmp8=rst.fields(0)
"X-i3d`o-P^0tmp9=rst.fields(4)
#[zL,j2y p4g%y0rst.close51Testing软件测试网G\1AJ[ Y
cnn.close
G)\ f3E5Z eao:`0Set rst=nothing51Testing软件测试网` A|9V2JQu
Set cnn=nothing51Testing软件测试网(o'v(Wv A{8_;mD
51Testing软件测试网 W.yQpbX7i4Z
'还有第3种打开excel的方式,“使用范围带有定义名称“,目前还没有搞明白。51Testing软件测试网 Qk;YK;k*FKI4v

%E)i,V7d gDCm(e0

TAG: QTP

 

评分:0

我来说两句

Open Toolbar