Get data from an Excel file without importing the data to the data table

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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)

sfilePathThe path and name of the excel file.
isheetThe sheet of the excel file. This can be an index number or the sheet name.
irowThe row number in the table.
icolumnThe 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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值