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

上一篇 / 下一篇  2007-06-12 19:04:07 / 个人分类:QTP

'ado读取excel文件中数据的2种方式
y}*h-t"D\T!M0a G0
FW+|^Q0Dim cnn,rst,strnn51Testing软件测试网;l:D/A p \ ~8G~W
strnn="Provider=MSDASQL.1;Persist Security Info=False;Data Source=ExcelFiles;"
` L;`#j9aQ @$T+R0strnn=strnn & "Initial Catalog=c:\REDB00000811.xls"51Testing软件测试网z_I8M [k
set cnn=createobject("ADODB.connection")
3Gb4Q+Gk0set rst=createobject("ADODB.recordset")51Testing软件测试网[3zj_}cwi
cnn.open strnn
7y Tr N L'@ VY0'使用表名跟美元符号51Testing软件测试网3K!Qmb2g
rst.open "select * from [sheet1$]",cnn,1,1
"UeH&ca)y0rst.movefirst
q1he {~w"nm6vn0tmp0=rst.fields(0)51Testing软件测试网T3T`7fA
tmp1=rst.fields(1)
.\-]^+V:L0tmp2=rst.fields(2)
E9s%S`2wZw"e)Iz0tmp3=rst.fields(3)
&G6I:dd!aZe]9H,}0tmp4=rst.fields(4)
!~8FuL ~h5s0tmp5=rst.fields(5)
xpZ:p-a f t0rst.movenext
#J\2mJ}Z#Oi0tmp6=rst.fields(0)
^;z#EE\4~0rst.close51Testing软件测试网$y"\)D-g#F0s:od
'与特定地址 (为示例, $ Sheet 1 [ A1:B10 ]) 指定区域。
^7d[3q1[Y.b({0rst.open "select * from [sheet1$A3:E5]",cnn '其实,数据是A4到E5的数据。A3所在的一行数据不                                             '取。51Testing软件测试网&?L:CcW
rst.movefirst
!J"x!nbQ.? b;}[,s0tmp7=rst.fields(0)51Testing软件测试网8E\5gv4\ E
rst.movenext
$|W:{[?(^.e'Mo0tmp8=rst.fields(0)
"z9xk3vg GQ7Vp(\0tmp9=rst.fields(4)51Testing软件测试网Vp;h:cV i O J
rst.close
e;g}y}2`0cnn.close51Testing软件测试网+E*c@8rQhH
Set rst=nothing51Testing软件测试网m\,B F~@*[;Y/S5_]r
Set cnn=nothing51Testing软件测试网j D/Ltz/tb|

TAG: QTP

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-04  
   1234
567891011
12131415161718
19202122232425
262728293031 

我的存档

数据统计

  • 访问量: 9348
  • 日志数: 16
  • 建立时间: 2007-06-12
  • 更新时间: 2007-06-21

RSS订阅

Open Toolbar