平平庸庸
vbs脚本 with excel数据驱动
上一篇 /
下一篇 2010-03-05 15:55:27
/ 个人分类:测试工具
Class SDateSheet
Dim oExcel
'根据列名返回列号
function getcol(fieldname)
Dim fieldno
fieldno=1
do while not oExcel.Cells(1,fieldno).Value=""
If fieldname=oExcel.Cells(1,fieldno).Value Then
getcol=fieldno
Exit do
End If
fieldno=fieldno+1
loop
End function
'配置需要的excel对象
Function setfileandsheet(filename,sheetname)
set Excel = CreateObject( "Excel.Application" )
oExcel.WorkBooks.Open( filename )
oExcel.WorkSheets(sheetname).Activate
oExcel.Visible = True
End Function
Function closeexl
oExcel.WorkBooks.Close
End Function
'根据列名和行号读取数据
Function Sgetdate(rowno,colname)
fieldno=getcol(colname)
Sgetdate=oExcel.Cells(rowno,fieldno).Value
End Function
End Class
Sub delay(obj)
Do
WScript.Sleep 1000
Loop Until CInt(obj.readyState)=4
End Sub
'以下是一个例子。直接请求google搜索某一个关键字。弹出显示response中的搜索框的内容
Dim rowno
'从第二行开始读数据,因为第一行是列名
rowno=2
Set aaa=new SDateSheet
'载入参数化文件并制定sheet
call aaa.setfileandsheet("E:\vbsscripttest\test.xls",1)
'开始操作,准备部分
Set ie = CreateObject("internetexplorer.application")
ie.Visible = true
'循环开始,
测试部分
While not aaa.oExcel.Cells(rowno,1).Value=""
Call delay(ie)
set qset=ie.document.getElementsByName("q")
msgbox qset(0).value
rowno=rowno+1
Wend
'结束操作
Call aaa.closeexl
Set aaa=nothing
Set ie=nothing
-----------------
以下是E:\vbsscripttest\test.xls 第一个sheet的内容
name | gander |
sunmx | male |
yemn | male |
vicky | female |
现在就用了name这个列。
收藏
举报
TAG: