Qtp
Read Excel
Data methodWhen building your own testing framework, or reading external data from Excel for checking, you must use the Excel COM object programming method. The readfile function in the script below implements this function, create an Excel application object, open an Excel file, and read the Excel data to an array. Arrrange = readfile ("D:/qtp/mywork/readexcelfiletest1/objecttree.xls", "Tree") 'msgbox ubound (arrrange, 1) 'msgbox ubound (arrrange, 2) 'msgbox arrrange (3, 1) 'input: 'sfilename: Excel file 'ssheetname: Form name' return: 'array function readfile (sfilename, ssheetname) dim oexcel dim osheet dim orange dim arrrange on error resume next 'create an Excel application object set oexcel = Createobject ("Excel. application ") if err. number <> 0 then msgbox "failed to initialize excel" & vbcrlf & _ "Please make sure Excel is installed ", vbcritical exit function end if on error goto 0 on error resume next 'Open the Excel file oexcel. workbooks. open (sfilename) If err. number <> 0 then msgbox "failed to load Excel files" & vbcrlf & _ "please ensure that the Excel file path is correct or the format is correct ", vbcritical exit function end if on error goto 0 'obtains the table's use range: Set osheet = oexcel. worksheets (ssheetname ). usedrange 'get all values set Orange = osheet from column A to column Z from row 1st to row 1,000th. range ("A1: z1000") 'converts Excel Data to array arrrange = Orange. value' close the workbook oexcel. workbooks. item (1 ). close 'exit Excel oexcel. quit set oexcel = nothing 'returns the array readfile = arrrangeend function containing Excel Data.