Forum Discussion

forrestaustin's avatar
forrestaustin
Contributor
6 years ago

What is COM and OLE Object / how to use excel past documentation example

I am trying to better understand how I can use TestComplete for reading and writing to excel files. Right now I am looking at the documentation about working with excel files via COM found here:

 

The documentation mentions a COM server and COM object, but what are these and what does COM stand for?

 

Also what is the OLE object? The article says "for more information about the excel object model" go to this documentation page from microsoft. The page doesn't ever mention what OLE stands for and it doesn't very well describe the model and how it can be used.

 

Can anyone give help provide me some clarification or information on these things. Ultimately I am trying to understand how to read and write data from excel files from various sheets within that excel file.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The articles, really, give everything you need to know, including sample code, for accessing an excel spreadsheet for reading directly and writing directly without needing to actually open the Excel application.

     

    But it really comes down to what you are intending to do.  What is in these spreadsheets that you want to use in your tests?  How do you want to use them?  What are you writing out and for what purpose?  Let us know a bit more of your use case and we'll see what we can do to help with implementation.

    • forrestaustin's avatar
      forrestaustin
      Contributor

      So I have a workbook with multiple sheets. I would like to access different sheets to obtain object tags from various cells. Then when I run a test I would like to paste values such as 'Pass' or errors into certain cells. 

       

      I looking at the following code from the TestComplete documentation:

       

      def ReadDataFromExcel():
        Excel = Sys.OleObject["Excel.Application"]
        Excel.Workbooks.Open("C:\\Work\\TestBook.xls")
      
        RowCount = Excel.ActiveSheet.UsedRange.Rows.Count
        ColumnCount = Excel.ActiveSheet.UsedRange.Columns.Count

      Some of my confusion was how to navigate to a specific sheet. Now that I am looking at it again is it just as simple as replacing the "ActiveSheet" from the code with the name of the sheet I am actually referring to?

       

      I am also trying to figure out how to represent specific cells as a range object. For example lets say I want to take the values from cells 5E, 6E,7E....20E. It looks like I need a way of representing  those as a range object but I am a little confused how I would do that.