gpt4 book ai didi

testing - 我如何比较QTP中的两行数据表

转载 作者:行者123 更新时间:2023-11-28 19:58:41 24 4
gpt4 key购买 nike

我如何比较QTP中的两行数据表

最佳答案

1)是否要比较QTP原生DataTable对象中的数据行?

  • 使用 SetCurrentRow 方法示例:objDataSheet.SetCurrentRow(intRow)

  • 使用 GetParameter 获取列名和单元格值sColName = objDataSheet.GetParameter(j).名称按索引取值:sCellValue = objDataSheet.GetParameter(j).Name按列名称取值:sCellValue = objDataSheet.GetParameter(sColName).Name

2) 您想比较 2 个不同的 Excel 工作表中的 2 行吗?您可以使用以下代码(取 self 的博客 http://automationbeyond.wordpress.com ,也可以查看其他示例)

Excel 应用程序必须安装在 PC 上。比较在占用范围内逐个单元格进行。不匹配的单元格标记为红色。

两个工作簿都必须存在并定义为带文件的完整路径。两个工作表都必须存在,并且可以定义为数字索引或字符串名称。

objParameter 是一个保留参数,用于实现“忽略大小写”、“舍入数字”等自定义比较。

Public Function ExcelWorksheetCompare(ByVal sWorkbook1, ByVal sWorksheet1, ByVal sWorkbook2, ByVal sWorksheet2, ByVal objParameter)
Dim boolRC, boolSheetExists
Dim FSO, XLHandle
Dim XLBook1, XLBook2, XLSheet1, XLSheet2
Dim Iter, objCell

‘Verify both files exist
Set FSO = CreateObject(”Scripting.FileSystemObject”)
boolRC = FSO.FileExists(sWorkbook1)
If Not boolRC Then
ExcelWorksheetCompare = FALSE
Exit Function
End If
boolRC = FSO.FileExists(sWorkbook2)
If Not boolRC Then
ExcelWorksheetCompare = FALSE
Exit Function
End If
Set FSO = Nothing

Set XLHandle = CreateObject(”Excel.Application”)
XLHandle.DisplayAlerts = False

‘Open workbook1
Set XLBook1 = XLHandle.WorkBooks.Open(sWorkbook1)

‘Verify sheet exists (1)
If isNumeric(sWorksheet1) Then
sWorksheet1 = CInt(sWorksheet1)
If (sWorksheet1 >0) AND (sWorksheet1<=XLBook1.Worksheets.Count) Then
Set XLSheet1 = XLBook1.Worksheets(sWorksheet1)
boolSheetExists = TRUE
Else
boolSheetExists = FALSE
End If
Else
boolSheetExists = FALSE
For Iter = 1To XLBook1.Worksheets.Count
If XLBook1.Worksheets(Iter).Name = sWorksheet1 Then
Set XLSheet1 = XLBook1.Worksheets(Iter)
boolSheetExists = TRUE
End If
Next
End If

If Not boolSheetExists Then
XLBook1.Close
XLHandle.Quit
Set XLBook1 = Nothing
Set XLHandle = Nothing

ExcelWorksheetCompare = FALSE
Exit Function
End If

‘Open workbook2
Set XLBook2 = XLHandle.WorkBooks.Open(sWorkbook2)

‘Verify sheet exists (2)
If isNumeric(sWorksheet2) Then
sWorksheet2 = CInt(sWorksheet2)
If (sWorksheet2 >0) AND (sWorksheet2<=XLBook2.Worksheets.Count) Then
Set XLSheet2 = XLBook2.Worksheets(sWorksheet2)
boolSheetExists = TRUE
Else
boolSheetExists = FALSE
End If
Else
boolSheetExists = FALSE
For Iter = 1To XLBook2.Worksheets.Count
If XLBook2.Worksheets(Iter).Name = sWorksheet2 Then
Set XLSheet2 = XLBook2.Worksheets(Iter)
boolSheetExists = TRUE
End If
Next
End If

If Not boolSheetExists Then
XLBook1.Close
XLBook2.Close
XLHandle.Quit
Set XLSheet1 = Nothing
Set XLBook1 = Nothing
Set XLBook2 = Nothing
Set XLHandle = Nothing

ExcelWorksheetCompare = FALSE
Exit Function
End If

‘Mark range

‘Compare and mark mismatches red
For Each objCell In XLSheet2.UsedRange
If objCell.Value <> XLSheet1.Range(objCell.Address).Value Then
objCell.Interior.ColorIndex = 3
Else
objCell.Interior.ColorIndex = 0
End If
Next

‘Save and close

XLBook1.Close

XLBook2.Save
XLBook2.Close

XLHandle.Quit

Set XLSheet1 = Nothing
Set XLSheet2 = Nothing
Set XLBook1 = Nothing
Set XLBook2 = Nothing
Set XLHandle = Nothing

ExcelWorksheetCompare = TRUE

End Function

关于testing - 我如何比较QTP中的两行数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1093167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com