股票切割线:QTP 读写外部Excel数据|QTP 资料-QTP技术论坛 - QTP技术论坛

来源:百度文库 编辑:九乡新闻网 时间:2024/05/06 09:47:30
'Read from Excel
Dim filepath,rowcount,i
filepath = pathfinder.Locate("C:\Users\Jevon\Desktop\TopView.xls")            'Excel path
DataTable.AddSheet("resultSheet")               'add new sheet to datatable
 
'import outside sheet  data into new sheet in the datatable
DataTable.ImportSheet filepath,"Test_Summary","resultSheet"   
rowcount = DataTable.GetSheet("resultSheet").GetRowCount  

'define the pass count,passrateand all case count  
Dim counts,passrate,bound                                                                        
counts = 0
reDim arraydata(rowcount)
bound = rowcount-9
'the tenth row is the first test case result
For i = 10 to rowcount
Datatable.SetCurrentRow(i)
 arraydata(i-10) =Datatable.Value("C","resultSheet")   'C is colume name
 If arraydata(i-10) = "Pass" Then
  counts=counts+1
 End If
Next
passrate=counts/bound


'write into Excel
Dim rowcount1
rowcount1=DataTable.GetSheet("PassRate").GetRowCount    'define a new  sheet named PassrRate
Dim row
row = rowcount1+1
DataTable.SetCurrentRow(row)
DataTable.Value("Name","PassRate") = "PassRate"
DataTable.Value("PassRate","PassRate") = passrate
'Write the second sheet of datatable into outside excel
DataTable.ExportSheet "C:\Users\Jevon\Desktop\TopView.xls",2