[英]QTP Compare Webtable Row with Excel ROW
I have a Webtable with 10 rows and similar table in Excel sheet with 100 rows of data. 我有一个包含10行的Web表,并且Excel工作表中有一个包含100行数据的类似表。
I need to check whether the 10 rows of webtable data is present in excel and also need to print in which row in exc enter image description here el it is matching. 我需要检查Excel中是否存在10行Web表格数据,还需要打印ex的哪一行在此处输入图像描述 ,以匹配它。
You haven't provided any details about your webtable, so I am assuming it has only column with multiple rows.if it has multiple initiate an array and then compare it. 您尚未提供有关Webtable的任何详细信息,因此我假设它只有一列包含多行。如果它有多个,则初始化一个数组然后进行比较。 It will return true if all the values in the excel matches with the webtable. 如果excel中的所有值都与webtable匹配,它将返回true。
Function Chktbl (coulmnname,sheetname,tblname)
Chktbl = True
Dim marray,excelop,weblistcount,l,m,k
l = datatable.LocalSheet.GetRowCount
For m = 1 To l
datatable.LocalSheet.SetCurrentRow m
excelop=trim(Datatable.Value(""&coulmnname,""&sheetname))
webcount = Browser("name:=.*").Page("title:=.*").Webtable("name:="&tblname).Rowcount
For k = 1 to webcount
marray = Browser("name:=.*").Page("title:=.*").Webtable("name:="&tblname).getcelldata (k,1)
If excelop= "" Then
Exit For
End If
If Ucase(excelop) = Ucase(trim(marray)) Then
Exit For
ElseIf k = webcount Then
reporter.ReportEvent micFail,"No match","Fail"
Chktbl = False
Exit For
End If
Next
Next 下一个
End Function 结束功能
First, read into an array your rows of data from the WebTable 首先,将WebTable中的数据行读入数组
Dim Table, CheckArray
Set Table = Browser("YourBrowser").Page("YourPage").WebTable("YourTable")
ReDim CheckArray(Table.RowCount - 1) ' Arrays index from 0, table rows from 1
For iLoop = 1 to Table.RowCount
CheckArray(iLoop-1) = Table.GetCellData(iLoop, 1)
Next
Once you have this array you can loop through each value and check against the Excel table. 一旦有了该数组,就可以遍历每个值并对照Excel表进行检查。 There are a few ways you could achieve this. 有几种方法可以实现此目的。
The least complex of these is 1, so I'll detail that approach here: 其中最小的复杂度为1,因此我将在此处详细说明该方法:
Datatable.Import("YourExcelFilePathHere.xls", Global)
iRowsToCheck = DataTable.GetRowCount
For iLoop = 0 to Ubound(CheckArray)
bFound = False
For iSubLoop = 1 to iRowsToCheck
DataTable.SetCurrentRow(iSubLoop)
If CheckArray(iLoop) = Datatable.Value("ColumnName") Then
bFound = True
Exit For
End If
Next
If bFound Then
CheckArray(iLoop) = CheckArray(iLoop) & " was found"
Else
CheckArray(iLoop) = CheckArray(iLoop) & " was not found"
End If
Next
This imports your excel file, and for each element in the webtable array, checks for it in the excel table. 这将导入您的excel文件,并针对webtable数组中的每个元素在excel表中进行检查。 If found, it exits and marks the array item as found. 如果找到,它将退出并将数组项标记为找到。 If it completes without setting bFound
to True then it wasn't found and updates accordingly. 如果在未将bFound
设置为True的情况下bFound
,则找不到它并进行相应更新。
You can then output the content of your array as you please to get your results. 然后,您可以根据需要输出数组的内容以获取结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.