Tuesday, February 1, 2011

How to retrieve data from excel sheet??

Function CopyrowfromExcel(strpath, Location, strTCRefval)

Dim arr(52)

Sheet=Location

Datatable.AddSheet Sheet

Set ObjectExcelApp = CreateObject("Excel.Application")

'Handling the Run time errors

On Error Resume Next

Err.Clear

Set ObjWorkbook=ObjectExcelApp.Workbooks.open (strpath)

Set ObjExcelSheet=ObjectExcelApp.worksheets(Trim(Sheet))

Rowscount=ObjExcelSheet.usedrange.rows.count

Columncount=ObjExcelSheet.usedrange.columns.count

'Below statements take column headers from external excel file andadd sameheaders to datatable

'Confirm there should not be any column header in the QTP datasheet

For j=1 to Columncount

ColumnHeader=ObjExcelSheet.cells(1, j).value

DataTable.GetSheet(Sheet).AddParameter ColumnHeader, ""

Next

'Below statements take desired row values and update in datatable

Flag=0

For k=1 to Rowscount

'Here I assume that first row always 'TCRef'.

strTCRef=ObjExcelSheet.cells(k, 1)

No comments:

Post a Comment