QTP - Data Table Object Methods


Data Table Object Methods:

Method NameDescriptionSyntax
AddSheetAdds the specified sheet to the run-time data tableDataTable.AddSheet(SheetName)
DeleteSheetDeletes the specified sheet from the run-time data tableDataTable.DeleteSheet SheetID
ExportExports the Datatable to a new file in the specified locationDataTable.Export(FileName)
ExportSheetExports a Specific Sheet of the Datatable in run-timeDataTable.ExportSheet(FileName,SheetName)
GetCurrentRowReturns the active row of the run-time data table of global sheetDataTable.GetCurrentRow
GetParameterCountReturns the number of columns in the run-time data Table of Global SheetDataTable.GetParameterCount
GetRowCountReturns the number of rows in the run-time data table of Global SheetDataTable.GetRowCount
GetSheetReturns the specified sheet from the run-time data table.DataTable.GetSheet(SheetID)
GetSheetCountReturns the total number of sheets in the run-time data table.DataTable.GetSheetCount
ImportImports a specific external Excel file to the run-time data table.DataTable.Import(FileName)
ImportSheetImports the specified sheet of the specific excel file to the destination sheet.DataTable.ImportSheet(FileName, SheetSource, SheetDest)
SetCurrentRowSets the Focus of the Current row to the Specified Row NumberDataTable.SetCurrentRow(RowNumber)
SetNextRowSets the focus of the next row in the run-time data tableDataTable.SetNextRow
SetPreviousRowSets the focus of the previous row in the run-time data TableDataTable.SetPrevRow

Data Table Object Properties:

Property NameDescriptionSyntax
GlobalSheetReturns the first sheet of the run-time data table.DataTable.GlobalSheet
LocalSheetReturns the Active local sheet of the run-time data table.DataTable.LocalSheet
RawValueRetrieves the raw value of the cellDataTable.RawValue ParameterID, [SheetID]
ValueRetrieves the value of the cell in the specified parameter.DataTable.Value(ParameterID, [SheetID])


Consider the below Data Table:

Get RowCount and Column Count
'Accessing Datatable to get Row Count and Column Count
rowcount = DataTable.GetSheet("Global").GetRowCount
msgbox rowcount      ' Displays 4
colcount = DataTable.GetSheet("Global").GetParameterCount
msgbox colcount		 ' Displays 3
val_rate = DataTable.Value("Rate","Global")
print val_rate   ' Displays 7%
val_ppl = DataTable.Value("Principal","Global")
print val_ppl	 ' Displays 2556
val_Time = DataTable.Value("Time","Global")
print val_Time	 ' Displays 5