Forum Discussion

vinkumar's avatar
vinkumar
Occasional Contributor
11 years ago

Create graph of test results in excel sheet.

Hi Team, I want to create graph of batch execution. Please help me with code how to create graph in excel sheet. Thanks, Vinay
  • TanyaYatskovska's avatar
    11 years ago
    Hi Vinay,

     


    You can add a chart to an Excel file via Excel's COM object. Look at this sample:


     




    'VBScript


    Sub AddChartToExcel


     


      Set objExcel = CreateObject("Excel.Application")


      objExcel.Visible = True


      Set objWorkbook = objExcel.Workbooks.Add()


      Set objWorksheet = objWorkbook.Worksheets(1)


      


      'Fill in a table for a chart


      objWorksheet.Cells(1,1) = "Tests"


      objWorksheet.Cells(2,1) = "Test Passed"


      objWorksheet.Cells(3,1) = "Test Failed"


      objWorksheet.Cells(4,1) = "Test with Warning"


      


      objWorksheet.Cells(1,2) = "Number of Tests"


      objWorksheet.Cells(2,2) = 3


      objWorksheet.Cells(3,2) = 5


      objWorksheet.Cells(4,2) = 1


      


      Set objRange = objWorksheet.UsedRange


      objRange.Select


      


      'Add a chart


      Set colCharts = objExcel.Charts


      colCharts.Add()


     


      Set objChart = colCharts(1)


      objChart.Activate


     


      objChart.HasLegend = FALSE


      objChart.ChartTitle.Text = "TestComplete Test Log"


      


      'Save results


      objWorkbook.SaveAs ("<File_Name>")


      


    End Sub