Forum Discussion

raskenny's avatar
raskenny
Occasional Contributor
13 years ago

Write values to specific cells in excel,

I am getting test data from an excel file (looping through project variables) and wish to write the result for a particular test into a specific column on the same row (in the same excel file) is it possible to do this while looping through the project variables ?



//sample code to use for your explanation



Project
["Variables"][txType].Reset();

  for(; ! Project["Variables"][txType].IsEOF();)

         { 

            

            //write or update some excel field for the current row being read

            

             Project ["Variables"][txType].Next();   

          }







any suggestions are welcome

Thanks

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    DB Table type project variables are read-only.  You cannot write values to them via the Project.Variables object.



    Out of curiousity, what is the purpose of writing values to the same spreadsheet?  Are you going to be using those values in a later test or are you using these values in an off-line validation of the results?  There may be a different way of achieving the same result.



    You can access Excel sheets directly using the Excel.Application object if you need to do so.  This will allow you to access the cells in read/write mode.  You can find some sample code to do so at http://smartbear.com/support/viewarticle/20878/.  Similar code can be adapted to loop through rows in in Excel the same way and then combine the two.
  • raskenny's avatar
    raskenny
    Occasional Contributor
    I plan to use these values to check against what's inserted in the DB for that row in excel. 

    for instance:

     i have 3 columns in excel named   Amount,cardNumber,orderId 

     ** Orderid column is blank since its generated by the app under test

     the DB table has the same columns as in Excel this time the orderId is inserted by the APP under test

    my goal was to insert the generated orderId and later use the OrderId field in a select statement to test if Amount and cardNumber from excel matches same fields in the Db table

     
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Have you considered using a DBTable checkpoint instead?  



    http://smartbear.com/support/viewarticle/11037/



    That way you don't have to write out the results to the Excel file, you can then just use the SQL table queries directly.  What I would do is loop through your excel sheet and execute each item and then run one DBTable checkpoint at the end.  



    Also, considering your usage of the Excel sheet, you might want to consider using DDT.ExcelDriver (http://smartbear.com/support/viewarticle/11915/) as the way to loop through your file.  This doesn't require you to do any Project variable work.
  • raskenny's avatar
    raskenny
    Occasional Contributor
    I will try DB table and Excel Driver as well and see if i need to re-design my test approach i am firly new to this tool .

    Thanks