DataTable Methods:
These methods are applied on either DataTable object or DTSheet object or DTParameter object. Here are the methods and their properties:
Points to remember –
UFT works only .xls extension file it won’t work with .xlsx
DataTable Object – Methods
Add Sheet:
Adds the specified sheet to the run time data table.
DataTable.AddSheet(“My Sheet”)
Here it will add a sheet in the Datatable with the name “My Sheet”
DeleteSheet:
Deletes the specified sheet from the run time data table.
DataTable.DeleteSheet “My Sheet”
Here it will delete an existing sheet in the Datatable whose name is “My Sheet”.
Export:
Exports the complete data table to the specified path.
DataTable.Export(“C:\abc.xls”)
ExportSheet:
Exports the current sheet to the specifed path.
DataTable.ExportSheet “C:\abc.xls”,1
GetCurrentRow: (for global sheet)
Retrieves the current row number of the global data sheet.
Row=DataTable.GetCurrentRow
Reporter.ReportEvent 1, “Row Number”, row
GetRowCount: (for global sheet)
Retrieves the number of rows in the longest column in the first sheet(global data sheet) in the run time data table.
Rowcount=DataTable.Get Sheet(“My Sheet”).GetRowCount
Reporter.ReportEvent 2, “There are” &rowcount, “rows in the data sheet”
GetSheet:
Retrieves the specified sheet in the run time data table.
DataTable.Getsheet(“My Sheet”).AddParameter(“Time”,”08:00”)
GetSheetCount:
Retrieves the total number of sheets in the run time data table.
Sheetcount=DataTable.GetSheetCount
Reporter.ReportEvent 0, “sheet number”, “There are” &sheetcount “sheets in data table”
Import:
Import the specified Microsoft Excel file to the run time data table.
DataTable.Import(“C:\abc.xls”)
ImportSheet:
Imports the specified sheet of Microsoft Excel file to the run time data table.
DataTable.ImportSheet”C:\abc.xls”, 1, ”Name”
SetCurrentRow:
Sets the specified row as the current(active) row in the run time data table.
DataTable.SetCurrentRow(2)
SetNextRow:
Sets the row next to the current row as the new current row in the run time data table sheet.
DataTable.GetSheet(“My Sheet”).SetNextRow
SetPrevRow:
Sets the row above the current row as the new current row in the run time data table sheet.
DataTable.SetPrevRow
DataTable Object - Properties
GlobalSheet Property:Description: Returns the first sheet in the datat table.
DataTable.GlobalSheet.AddParameter “Time”,”08:00”
LocalSheet Property:
Description: Returns the current (active) sheet of the data table.
MyParam=DataTable.LocalSheet.AddParameter “Time”,”09:00”
RawValue Property:
Description: Returns the raw value of the cell in the specified parameter of the current row of the data table. The raw value is the actual string written in the cell before the cell is computed, such as the actual text from a formula.
FormulaVal=DataTable.RawValue(“Date”,”ActionA”)
Value Property:
Description: Data table default property. Retrieves or sets the value of the cell in specified parameter and the current row of the data table.
DataTable.Value(2,3)=”New York”
DTParameter – Methods
DtSheet.AddParameter: (Adds a new column.)
DataTable.GetSheet(“dtGlobalSheet”).AddParameter “NewColumnName”,”FirstRowVaule”
DtSheet.GetParameter:
Description: Retrieves the specified parameter from the run time data table sheet.
DataTable.GetSheet(“My Sheet”).GetParameter(“Destination”)
DtParameter – Properties
Name Property:
Description: Retrieves the name of the parameter in run time data table.
ParamName=DataTable.LocalSheet.AddParameter(“NewColumnName”,”Row1Value”).Name
RawValue Property:
Description: The raw value of the cell in the current row of the parameter in the run time data table. The raw value is the actual string written in the cell before the cell is computed, such as the actual text from a formula.
The following example uses the RawValue property to find the formula used in current row of the Date column in the ActionA sheet of the run time data table.
The statement below runs the Value:=Now()
FormulaVal=DataTable.GetSheet(“ActionA”).GetParameter(“Date”).RawValue
Value Property:
Parameter default property. Retrieves or sets the value of cell in the current row of parameter in the run time data table.
DataTable.GetSheet(“ActionA”).GetParameter(“Destination”).Value=”New York”
ValueByRow Property:
Retrieves the value of the cell in the specified row of the parameter in the run time data table.
DataTable.GetSheet(“ActionA”).GetParameter(“Destination”).ValueByRow(4)
DTSheet Methods
AddParameter Method:
Add the specific parameter(column) to the sheet in Run Time data table, sets the value of the first row to the specified value, and returns the parameter so that you can directly set or retrieve properties of new parameter in same statement.
Variable=DataTable.AddSheet(“My Sheet”).AddParameter(“Time”,”08:00”)
DeleteParameter Method:
Deletes the specified parameter from the sheet in run time data table.
DataTable.GetSheet(“My Sheet”).DeleteParameter(“Time”)
GetCurrentRow Method:
Returns the row number of the current(active) row in the run time data table sheet.
Rownum=DataTable.GetSheet(“My Sheet”).GetCurrentRow
Reporter.ReportEvent 1, “Row Number”, rownum
GetParameter Method:
Returns the specified parameter from the run time data table sheet.
DataTable.GetSheet(“My Sheet”).GetParameter
GetParameterCount Method:
Returns the total number of parameters(columns) from the run time data table sheet.
Paramcount=DataTable.GetSheet(“My Sheet”).GetParameterCount
Reporter.ReportEvent 2, “There are”, ¶mcount, “columns in this sheet”
GetRowCount Method:
Returns the total number of rows in the longest column in the run time data table sheet.
rowcount=DataTable.GetSheet(“My Sheet”).GetRowCount
Reporter.ReportEvent 2, “There are”, &rowcount, “active rows in this sheet”
SetCurrentRow Method:
Sets the specified row as the current row in the run time data table sheet.
DataTable.GetSheet(“My Sheet”).SetCurrentRow(2)
SetNextRow Method:
DataTable Object – Methods
Sets the row next to the current row as the new current row in the run time data table sheet
DataTable.GetSheet(“My Sheet”).SetNextRow
SetPrevRow Method:
Sets the row above the current row as the new current row in the run time data table sheet.
DataTable.GetSheet(“My Sheet”).SetPrevRow
DTSheet Properties:
Name Property:
Returns the name of the run time data table sheet.
Sheetname=DataTable.LocalSheet.Name
Reporter.ReportEvent 1, “The active sheet is”, sheetname