Comment puis-je comparer deux rangées de datatable dans QTPComment puis-je comparer deux rangées de datatable dans QTP
Répondre
1) Est-ce que vous voulez comparer les lignes de données dans l'objet DataTable natif de QTP?
Utilisation procédé setCurrentRow Exemple: objDataSheet.SetCurrentRow (intRow)
Utilisation GetParameter pour accéder nom de la colonne et la valeur de cellule sColName = objDataSheet.GetParameter (j) .Nom Valeur par index: sCellValue = objDataSheet.GetParameter (j) .Nom Valeur par nom de col: sCellValue = objDataSheet.GetParameter (sColName) .Nom
2) Avez-y Vous voulez comparer 2 lignes dans 2 feuilles de calcul Excel distinctes? Vous pouvez utiliser le code suivant (tiré de mon blog http://automationbeyond.wordpress.com, voir aussi d'autres exemples)
L'application Excel doit être installée sur le PC. La comparaison va cellule par cellule dans la plage occupée. Les cellules mésappariées sont marquées en rouge.
Les deux classeurs doivent exister et être définis comme chemin complet avec le fichier. Les deux feuilles de calcul doivent exister et peuvent être définies comme un index numérique ou un nom de chaîne.
objParameter est un paramètre réservé à mettre en œuvre comparaison personnalisée comme « ignorer la casse », « arrondir les chiffres », etc.
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
- 1. comment comparer les deux date
- 2. Comment comparer deux référentiels git?
- 3. Comparer deux valeurs
- 4. problème de comparer deux tableaux
- 5. regex comparer deux nombres
- 6. Comment puis-je comparer deux révisions de git dans Eclipse?
- 7. Comparer deux XmlNodes en C#
- 8. Comment pouvez-vous comparer deux pipelines dans Bash?
- 9. Comment comparer deux tableaux d'objets DataRow dans PowerShell?
- 10. Comment puis-je comparer deux valeurs glob dans Oracle
- 11. Comment puis-je comparer deux fichiers dans un fichier batch?
- 12. Comment comparer deux ensembles de données pour l'égalité
- 13. Comment puis-je comparer deux variables/colonnes de type NTEXT
- 14. Comment comparer les valeurs de deux contrôles avec un déclencheur?
- 15. Rangées imbriquées dans une rangée
- 16. Comparer deux tableaux contenant des chaînes?
- 17. jQuery - comment sélectionner toutes les lignes de table entre deux rangées de table en même table
- 18. Comparer deux chaînes en ignorant certains caractères
- 19. comment comparer deux fichiers et extraire la différence?
- 20. JavaService et QTP
- 21. Comparer deux dates - sans heure et seconde
- 22. SQL pour comparer deux horodatages unix?
- 23. comment afficher une table avec zéro rangées dans UITableView
- 24. Comment comparer dans RDLC
- 25. fichier XML de charge QTP
- 26. Comment puis-je comparer deux champs datetime mais ignorer l'année?
- 27. Comment puis-je comparer deux fichiers en contexte complet?
- 28. C# meilleure façon de comparer deux heures de la journée
- 29. Comment comparer si deux objets sont vraiment le même objet?
- 30. Comment comparer deux hachages en Perl sans utiliser Data :: Compare?