Create an Excel object using VBScript
The function below will allow to you to extract data from an external Excel file (specifying the sheet) without importing the file to the QuickTest data table. The function uses automation objects to create an Excel object.
GetValueInFile (sfilePath, isheet, irow, icolumn)
| sfilePath | The path and name of the excel file. |
| isheet | The sheet of the excel file. This can be an index number or the sheet name. |
| irow | The row number in the table. |
| icolumn | The column number in the table. |
Function GetValueInFile (sfilePath, isheet, irow, icolumn)
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Workbooks.Open sfilePath
Set NewSheet = ExcelObj.Sheets.Item(isheet)
value = NewSheet.Cells(irow,icolumn)
ExcelObj.Application.Quit
Set ExcelObj = Nothing
GetValueInFile = value
End Function
Example:
dim filename
filename = "D:\temp\Test.xls"
msgbox GetValueInFile(filename,1,2,2)
msgbox GetValueInFile(filename,"Sheet1",1,1)
msgbox GetValueInFile(filename,2,2,2)
msgbox GetValueInFile(filename,3,1,1)

本文介绍如何利用VBScript创建Excel对象,从外部Excel文件中提取指定工作表的数据,无需导入到QuickTest数据表。通过提供的示例代码,演示了如何通过路径、工作表名、行号和列号获取所需数据。
31万+

被折叠的 条评论
为什么被折叠?



