|
我贴一段QTP对xls文件的读写代码吧。
Set xlApp = CreateObject("Excel.Application")
xlApp.application.visible=true
Set xlbook=xlApp.WorkBooks.Open("d:\nonodata.xls")
Set xlSheet = xlBook.Worksheets("Sheet1")
systemutil.Run "C:\windows\system32\calc.exe"
For i=2 to 5
input1= xlSheet.cells(i,2).value
expression = xlSheet.cells(i,3).value
input2= xlSheet.cells(i,4).value
expresult = xlsheet.cells(i,5).value
Window("计算器").Activate
Window("计算器").Type cstr(input1)
Window("计算器").WinButton("operator").SetTOProperty "text",cstr(expression)
Window("计算器").WinButton("operator").Click
Window("计算器").WinEdit("Edit").Type cstr(input2)
Window("计算器").WinButton("=").Click
outvalue = cstr(window("计算器").WinEdit("Edit").GetROProperty ("text"))
Window("计算器").WinButton("C").Click
actresult = replace(outvalue,".","")
If trim(cstr(expresult)) <> trim(cstr(actresult)) Then
reporter.ReportEvent 1,"测试结果","失败"
xlsheet.cells(i,7) = "NOK"
xlsheet.cells(i,7).font.color = vbred
else
reporter.ReportEvent 0,"测试结果","成功"
xlsheet.cells(i,7) = "OK"
xlsheet.cells(i,7).font.color = vbgreen
End If
xlSheet.cells(i,6) = actresult
xlSheet.cells(i,6).font.color = vbblue
Next
Window("计算器").Close
xlbook.save
xlApp.DisplayAlerts = False
xlbook.close(true)
xlApp.quit
Set excel=nothing
p.s.:xls文件内容如下:
caseID input1 expression input2 expresult actresult conclusion
1 4 + 2 6
2 3 - 2 1
3 3 * 5 15
4 6 / 2 20 |
|