Forum Discussion

XBug's avatar
XBug
Contributor
7 years ago

How to test the content of an Excel spreadsheet?

Hi,

 

What I would like to do is the following:

  1. Open an Excel File from a directory
  2. Check if the content of the column in Excel file meets a certain criteria

 

I have done the first step but is getting stuck on the 2nd one. I am having trouble with mapping the objects of the Excel spreadsheet.

 

Looking forward to anyone's input.

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I wouldn't even bother with the OleObject... use a DDT.ExcelDriver to loop through the rows and check the value of each cell in the indicated column. Built a list of all the differences and report any at the end.
    • XBug's avatar
      XBug
      Contributor

      tristaanogre, how do I do that via Keyword Test? Note that I do not use scripts and mainly use Keyword tests.

       

      shankar_r, I do not use scripts, only Keywords. See ExcelVerification.png. The property checkpoint there only checks the spreadsheet's filename as that's the only thing I can do for now with my limited knowledge.

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi, 

     

    Simple sample for validating content in excel.

     

    Sub CompareValue(str_ComVal)
      Dim Excel
    
      Set Excel = Sys.OleObject("Excel.Application")
      Excel.Workbooks.Open("D:\Users\Documents\Testss.xlsx")
    
      If Excel.ActiveWorkbook.Sheets.Item("Sheet1").Range("A1") = str_ComVal Then
          Log.Checkpoint("Matched")
      Else
          Log.Error("Not matched")
      End If
      
      Excel.Quit
      Set Excel = Nothing
    End Sub
  • shankar_r's avatar
    shankar_r
    Community Hero

    Can you show us the code which you trying for this scenario?