Function to check to see if column exits in QTP excel sheet
This function will help you in checking if the column exists or not. If the column exists it returns true value, otherwise false. It works for both GlobalSheet or LocalSheet
1. Copy Paste this piece of code in your function library (For example Test.qfl)
2. Associate the Test.qfl with your current test
3. Use the function J
1. Copy Paste this piece of code in your function library (For example Test.qfl)
public Function CheckExcelSheetColumnExists(ByVal strSheetName, ByVal strColumnName)
Dim result
Dim strTestColumn
If strSheetName = dtGlobalSheet Then
strSheetName = dtGlobalSheetName
elseif strSheetName = dtLocalSheet then
strSheetName = DataTable.LocalSheet.Name
End If
result = false
excelColumnCount = DataTable.GetSheet(strSheetName).GetParameterCount
For i = 1 to excelColumnCount
columnInExcel = DataTable.GetSheet(strSheetName).GetParameter(i).Name
If columnInExcel = strColumnName Then
result = true
End If
Next
CheckExcelSheetColumnExists = result
End Function
2. Associate the Test.qfl with your current test
3. Use the function J
If referring action's local sheet
CheckExcelSheetColumnExists('dtLocalSheet", ColumnA")
If referring test's globalsheet sheet
CheckExcelSheetColumnExists('dtGlobalSheet", ColumnA")
Comments
Post a Comment