Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search in Excel / DataTable
#3
Solved: 11 Years, 5 Months ago
Hi vramu1,

Thank you very much for your answer.

When I tried to understand your approach, I realized that you can really integrate Excel into QTP, like in programming languages like VB or C#, with the CreateObject-method.

The only catch is that within QTP the actual methods and properties of the object instantiated with CreateObject (in this case the Excel, Workbook, Sheet, ..-objects) are not recognized. So you really have to know the methods you like to call.

I helped myself with opening Visual Studio and creating VB-code doing exactly my task and copying this code into the Expert View of QTP.

Now the search for the specific row works very fast.
Thank you.

And here is my code, how I did it:

Code:
referenceNumber = DataTable("referenceNumber", dtLocalSheet)

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open(DataTable("Filename", dtGlobalSheet))

Set actualValues  = objWorkbook.Worksheets(DataTable("Sheetname", dtGlobalSheet))

foundRow = actualValues.Columns(2).Find(referenceNumber).Row

countCols = actualValues.UsedRange.Columns.Count
countRows = actualValues.UsedRange.Rows.Count

If foundRow > countRows Then
    Reporter.ReportEvent micFail, "Item " & referenceNumber & " not found in Report", ""
else
   Reporter.ReportEvent micPass, "Item " & referenceNumber & " found in Report", "Item " & referenceNumber & " found in Report in line " & foundRow
End If
Reply


Messages In This Thread
Search in Excel / DataTable - by idolast - 01-22-2008, 06:41 PM
RE: Search in Excel / DataTable - by idolast - 01-23-2008, 05:38 PM
RE: Search in Excel / DataTable - by newqtp - 01-23-2008, 11:21 PM
RE: Search in Excel / DataTable - by vramu1 - 01-24-2008, 06:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  CyberArk CorePAS REST API to search for accounts pramod 0 866 06-29-2023, 03:11 PM
Last Post: pramod
  Search All Test scripts For a Function? AndyBSG 1 2,786 02-19-2015, 04:15 AM
Last Post: supputuri
  Search for a string in all the files under all subdirectory Mahesh27 1 2,245 07-03-2013, 03:24 PM
Last Post: Sathiya
  Testing Search box kriday 1 2,555 06-26-2013, 08:51 AM
Last Post: basanth27
  Search for a word in excel string QAVA 6 9,461 11-23-2012, 11:17 AM
Last Post: vinod123

Forum Jump:


Users browsing this thread: 2 Guest(s)