有谁知道,怎么样能把EXCEL表中数据导入和导出呢,用代码写的那种,我在网上找了点,可是运行不了,我看不懂了,先放上来,如果谁看懂了,帮忙解释下 我想将运行完的结果,比如"PASS"或是“FAILED”写入到EXCEL中,如何写代码? 我贴一段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) 我走到这步就运行不下去了,提示operator 找不到,怎么解决
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 |