how to access the excel file as database in UFT?
We mostly use the excel file in UFT by using the excel object but it can also be accessed as a database and you can run the queries on different excel sheets as the database tables.
You can use the ADODB connection to use the excel as database. Below is the code snippet to use excel as a database.
Set Conn = CreateObject("ADODB.Connection")
Set RecSet= CreateObject("ADODB.RecordSet")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ExcelFilePath& ";Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"";"
If you want to access the .xlsx file then please change "Excel 8.0" to "Excel 12.0".
After making the successful connection, you need to provide the query and execute it using the recordset in the same way you do it for database tables. But here you need to provide the excel sheet name as database tables.
Query = "Select * From [" & sheetName & "$]"
RecSet.Open Query, Conn, 3, 3, 1
Do Until RecSet.EOF
for i=0 to RecSet.Fields.Count
msgbox RecSet(i).Value
Next
RecSet.MoveNext
Loop
Have a great time in scripting.
Comments
Post a Comment