Interview Questions

How to read .xls file contents without using the ddt wizard?

SilkTest Questions and Anwsers


(Continued from previous question...)

91.How to read .xls file contents without using the ddt wizard?

How to read .xls file contents without using the ddt wizard? [the result file is result.res Parsed it to result.rex file such that I can read this file The test case file is testcase.xls
Now I need to search the contents of that file and next to the cell I need to update the result of the rex file
I succeeded to read a .rex file
Now I need to know is there any simple way to read the xls file and need to update this file
I tried with one approach and further i strucked
[ ] STRING gsDSNConnect = "DSN=Segue DDA Excel;DBQ=C:\abcdef.xls;UID=;PWD="
[ ] HDATABASE DBHandle
[ ] HSQL SQLHandle
[ ] DBHandle=DB_Connect(gsDSNConnect)
[ ]
[ ] SQLHandle=DB_ExecuteSql(DBHandle,"select ")
From here on wards I didn't got the idea how to read the contents of .xls file)



[-] List of anytype ReadingDataFromXLS(string sFileName,inout anytype aRecordName, string sQuery optional)
[ ]
[ ] List of anytype lrRecordData
[ ]
[ ] HDATABASE hdbc
[ ] HSQL hstmnt
[ ]
[ ] string sFilePath = "{sFileName}.xls"
[-] do
[ ]
[-] if (!SYS_FileExists(sFilePath))
[ ] Log.Write("File does not exists in specified path i.e {sFilePath}, Please check the existance of the file.","ERROR")
[-] else
[ ]
[ ] // connect to xls file
[ ] hdbc = DB_Connect ("DSN=Segue DDA Excel;DBQ={sFilePath}")
[ ]
[-] if (sQuery != NULL)
[ ] // retrieve info from Excel worksheet
[ ] hstmnt = DB_ExecuteSql (hdbc, sQuery)
[-] else
[ ] // retrieve info from Excel worksheet
[ ] hstmnt = DB_ExecuteSql (hdbc, "SELECT * FROM `Sheet1$`")
[ ]
[ ] //Loop through excel file for retriving the data
[-] while (DB_FetchNext (hstmnt, aRecordName))
[ ] ListAppend(lrRecordData,aRecordName)
[ ]
[ ] //release SQL stmt resources
[ ] DB_FinishSQL (hstmnt)
[ ]
[ ] // Disconnect
[ ] DB_Disconnect (hdbc)
[ ]
[ ] //return the excel data in record structure
[ ] return lrRecordData
[ ]
[-] except
[ ] Log.Write("There may be problem in reading the excel file.. Please close all opened Excel files","ERROR")

(Continued on next question...)

Other Interview Questions