Featured

Showing posts with label Excel Operations in QTP. Show all posts
Showing posts with label Excel Operations in QTP. Show all posts

0 Upload file in QC thru QTP


''// This function will upload any file into QC as attachment.

filepath="C:\Auto\Results\results_xyz_02.xls"

Public function z_attachtoQC(filepath)
                 Set nowTest = QCUtil.CurrentTestSet
                 Set attachmentPath = nowTest.Attachments
                 Set nowAttachment = attachmentPath.AddItem(Null)

                 'Replace with the path to your file:

                 nowAttachment.FileName = filepath
                 nowAttachment.Type = 1
                 nowAttachment.Post()

End Function

Read more

0 Reading from an EXCEL file in QTP - VBScript

Pre-requisite : Have an excel file names c:\data.xls with data in 3 rows and 3 columns, remember to close the excel file before running the script.

QTP Code to read an excel file

Dim arr() ' Declares the array arr

zRead_frm_Excel "c:\data.xls","Sheet1",1

For i=0 to ubound(arr)-1
msgbox arr(i)
next


' This function is to read and close the xl | arg1=path of xl, arg2=sheet name, arg3=startn row
Function zRead_frm_Excel(xl,sheet,srt_row)

Set xlApp = GetObject("","Excel.Application")
xlApp.visible = true
Set xlWrkbk = xlApp.Workbooks.Open(xl)
Set xlWrksht = xlWrkbk.Worksheets(sheet) ' Data is the name of the sheet
intStartRow = srt_row ' Row from whcih you need to start
row_cnt= xlWrksht.UsedRange.Rows.Count
ReDim arr(row_cnt)
ub= ubound(arr)-1
i=0
For intRow = intStartRow to xlWrksht.UsedRange.Rows.Count
strAccountNumber = Trim(xlWrksht.Range("A" & intRow)) ' Column A
strAccuntName = Trim(xlWrksht.Range("B" & intRow)) ' Column B
dtDate = Trim(xlWrksht.Range("C" & intRow)) ' Column C
arr_value=strAccountNumber&strAccuntName&dtDate
arr(i)=arr_value
i=i+1
Next
xlApp.Quit
Set xlApp = Nothing
zRead_frm_Excel=arr

End Function
Read more
  • Recent Posts

     
    © QTPCode | Design by Blog template in collaboration with Concert Tickets, and Menopause symptoms
    Powered by Blogger