How to Import, Read, Change Data from EXCEL in QTP/UFT
Steps to Import, Read, Change Data from EXCEL
In this tutorial, we will be working with Excel with Micro Focus UFT
Consider we want to import the following Sales.xls
Once imported into HP UFT, the top row becomes the column header. So structure your data accordingly.
The Syntax to import entire Excel file is
DataTable.Import(FileName)
In our case
Datatable.import "D:\Automation\Sales.xls"
The Syntax to import a particular sheet is
DataTable.ImportSheet(FileName, SheetSource, SheetDest)
Use the method Getrowcount to get number of rows in the sheet
Datatable.import "D:\Automation\Sales.xls"row = Datatable.getsheet(1).Getrowcount MsgBox row
To set the current row to use the method SetCurrentRow
Datatable.import "D:\Automation\Sales.xls"DataTable.SetCurrentRow(1)
‘ In the code below, 1 is the sheet number
Row1= Datatable.Value("Year",1) DataTable.SetCurrentRow(2) Row2= Datatable.Value("Year",1) MsgBox("Year Row 1 =" & Row1 & " Year Row 2 =" & Row2 )
Use the Value method to change data in the imported sheet. Use the Export method to export the Excel