💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 如何在 QTP / UFT 中从 EXCEL 导入,读取,更改数据 > 原文: [https://www.guru99.com/using-excel-with-qtp-hp-uft.html](https://www.guru99.com/using-excel-with-qtp-hp-uft.html) 在本教程中,我们将通过 Micro Focus UFT 使用 Excel。 考虑我们要导入以下 Sales.xls ![Using Excel with QTP ](https://img.kancloud.cn/0d/89/0d890f19a5d803133e5fa31f27e0f927_617x309.png "Using Excel with QTP ") **导入 HP UFT 后,第一行成为列标题。 因此,相应地构建数据**。 导入整个 Excel 文件的语法是 ``` DataTable.Import(FileName) ``` 就我们而言 ``` Datatable.import "D:\Automation\Sales.xls" ``` ![Using Excel with QTP ](https://img.kancloud.cn/15/ad/15ad20eee8ddbc5e03b09f27eea9f7df_591x609.png "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 ](https://img.kancloud.cn/03/97/0397436222efc7bcffb3ec364d9c309e_678x602.png "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 ](https://img.kancloud.cn/78/65/7865c999ed755fa241559778b7ce7459_743x523.png "Using Excel with QTP ") 使用**值**方法更改导入工作表中的数据。 使用**导出**方法导出 Excel ![Using Excel with QTP ](https://img.kancloud.cn/be/6d/be6dfbb8c77527c83fd9db546b1c8a91_559x511.png "Using Excel with QTP ") ![Using Excel with QTP ](https://img.kancloud.cn/41/c7/41c7c10dd9b3468f01c447ef1512ae98_770x453.png "Using Excel with QTP ")