08-03-2012, 03:51 PM
Hi Indranil,
It is not possible within QTP itself although I do something very similar including appending date and time to the excel sheet. When you perform the export write the full path and filename to an environment variable and at the end of the test call a function similar to below to update the formatting passing the environment variable as the file:
It is not possible within QTP itself although I do something very similar including appending date and time to the excel sheet. When you perform the export write the full path and filename to an environment variable and at the end of the test call a function similar to below to update the formatting passing the environment variable as the file:
Code:
Function FormatExcel(cFile)
Dim xl, wb, ws, iRow
'
set xl=CreateObject("excel.application")
set wb=xl.workbooks.open (cFile)
set ws=wb.worksheets(1) ' Assume global sheet is first
xl.DisplayAlerts = False ' Supress any messages from excel
iRow = Datatable.GetRowCount ' Use the count of the current datasheet
For x = 1 to iRow + 1 ' +1 to skip the header row
If ws.Cells(x, 2).Value = "Pass" Then ' 2 is the column number with pass, fail
ws.Cells(x, 2).Style = "Good" ' Use built in excel styles for the colour
ElseIf ws.Cells(x, 2).Value = "Fail" Then
ws.Cells(x, 2).Style = "Bad"
ElseIf ws.Cells(x, 2).Value = "Warning" Then
ws.Cells(x, 2).Style = "Input"
End If
Next
' Save and close the file
wb.SaveAs cFile, True
wb.close
set ws=nothing
set wb=nothing
set xl=nothing
'
End Function