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

Steps To Import,Read,Change Data From Excel

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"

Steps To Import,Read,Change Data From Excel

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

Steps To Import,Read,Change Data From Excel

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  )

Steps To Import,Read,Change Data From Excel

Use the Value method to change data in the imported sheet. Use the Export method to export the Excel

Steps To Import,Read,Change Data From Excel

Steps To Import,Read,Change Data From Excel