如何在QTP/UFT中导入、读取、更改EXCEL中的数据

在本教程中,我们将使用带有Micro Focus UFT的Excel,要导入以下sales.xls

Using Excel with QTP
Using Excel with QTP

导入HP UFT后,顶行将成为列标题。因此,相应地组织数据。

导入整个Excel文件的语法为

DataTable.Import(FileName)

具体实例:

Datatable.import "D:\Automation\Sales.xls"
Using Excel with QTP
Using Excel with QTP

导入特定工作表的语法为

DataTable.ImportSheet(FileName, SheetSource, SheetDest)

使用GetrowCount方法获取工作表中的行数

Datatable.import "D:\Automation\Sales.xls"row = Datatable.getsheet(1).Getrowcount MsgBox row
Using Excel with QTP
Using Excel with QTP

将当前行设置为使用方法SetCurrentRow

Datatable.import "D:\Automation\Sales.xls"DataTable.SetCurrentRow(1)

‘在下面的代码中,1是页码

Row1=  Datatable.Value("Year",1)
       DataTable.SetCurrentRow(2)
       Row2=  Datatable.Value("Year",1)
              MsgBox("Year Row 1 =" & Row1 & "    Year Row 2 =" & Row2  )
Using Excel with QTP
Using Excel with QTP

使用Value方法更改导入的工作表中的数据。使用Export方法导出Excel

Using Excel with QTP
Using Excel with QTP
Using Excel with QTP
Using Excel with QTP

IT赶路人

专注IT知识分享