How to read Excel Data Using qtp

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.