Exporting data sheets into excel
I am trying to tweak this code to be able to export my Global sheet results on 2 columns in a single excel worksheet. Here's the exact scenario:
I have one instance of QTP that runs the same tests on a legacy version of an application (called APP1) I am testing. We ALSO have the new version of this app (APP2) I run a QTP test on as well. What I would love to do is have APP1 export to an APP1 column in the Excel worksheet and when I run the other test on APP2, it then exports to the 2nd column next to APP1 results it in the same worksheet. The automation scripts aren't executed at the same time so no sharing violation issues with the Excel sheet.
Here's the code i have so far.. any help would be appreciated.
Set oDesc = Description.Create()
oDesc("html id").Value = "protocolNumber"
oDesc("micclass").Value = "WebElement"
Set oChild = Browser("Browser").Page("Page_8").ChildObjects(oDe sc)
intTableCount = oChild.Count
intCurTblRow = DataTable.LocalSheet.GetCurrentRow
For intObj = 0 to intTableCount -1
DataTable.LocalSheet.SetCurrentRow intObj +1
DataTable("ProcNumCTOL2") = oChild(intObj).GetROProperty("innertext")
'DataTable.ExportSheet "C:\Temp\Adv Search Results.xlsx", ProcNum
'DataTable.Export "C:\Temp\Adv Search Results.xlsx"
DataTable.Export "\\infoscidiv\users\fsookiasian\Temp\CTOL2 - Type of Study_B_1.xls"
If you need to execute the same script on different applications App1 and App2. Try to find a property value which could distinguish App1 and App2 e.g. could be something like version number could be anything.
Assuming applications are distinguishable using version number then, when version number = x have your values populated in column1 and otherwise have your values populated in column2.
Being said that, you can use below code to have your values populated in the external excel sheet -
'Following would set column_num for each versioned Application i.e, App1 and App2 in your case
If version_num = x Then
Column_Num = 1
Column_Num = 2
'Your code goes here
'Following piece of code should satisfy your need
Set oExcel = CreateObject("Excel.Application")
Set owb = oExcel.Workbooks.Open("Excel path")
For rowNum = 1 to intTableCount - 1 'Check this once
oExcel.Cells(rowNum,Column_Num).Value = oChild(intObj).GetROProperty("innertext")
'Destroy object instances
Let know if it solved your problem.
For your scenario you have to do coding like below
If Excel.exist then (Check for the availability of the Excel, if so you have already executed the test already)
Import the excel
Check for the column number
Write the test output in 2nd column
Export the sheet
Write the test output in 1st column
Export the sheet
you can modify your code based on above logic