TA的每日心情 | 奋斗 2014-12-18 10:31 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
代码如下:
本帖最后由 feiyunkai 于 2010-11-4 18:08 编辑
COM接口 :
Set excelApp = CreateObject("Excel.Application")
Set newBook = excelApp.Workbooks.open(excelpath) 'excelpath为EXCEL路径
For i= 1 to 10000 '若第N行是用例起始行,则修改为for i=N to 10000 ,10000是任意一个大于用例总数的数字
CaseName=newBook.WorkSheets(SheetName).Cells(i,j) 'SheetName是用例所在Sheet,i是用例所在行,j是用例所在列
if CaseName<>"" then
print CaseName
Else
exit for
End if
Next
excelApp.Workbooks.Close
excelApp.Quit
Set newBook=nothing
Set excelApp =nothing
ADO接口:
Set conn= createobject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&excelpath&";Extended Properties=Excel 8.0" 'EXCEL97-2003,excelpath为EXCEL所在路径
'conn.Open "Provider=Microsoft.Jet.OLEDB.12.0;Data Source="&excelpath&";Extended Properties=Excel 12.0" 'EXCEL2007要安装OLEDB12.0不然会报错
Set rs=CreateObject("ADODB.Recordset") '创建记录集
rs.Open "Select CaseName from [Sheet1$] ",conn 'SQL语句查询所有用例,CaseName 为用例所在列的列名,[Sheet1$]为用例所在Sheet
Do
If not rs.eof Then
CaseName=rs("CaseName")
print "用例名称:"&CaseName
rs.MoveNext
else
print "没有用例"
End If
loop until rs.eof=true
conn.close
Set rs=nothing
Set conn = nothing
'若调试未通过,可以MSN给我发信息,相互学习!我的MSN:yunkai614221@live.cn |
|