rs79
rs79

Reputation: 2321

Writing into the same input Excel File

I have a data driven QTP test script that retrieves input parameters from an Excel File. Is there a way to actually write the results of the test into that Excel file, as well?

For instance, My input file has the following Columns:

  1. User ID
  2. Password
  3. Login Result

The test script uses the User ID and Password are the input parameters to login to the system. The script then checks whether the login attempt was successful and then should write the result alongside in the Login Result column.

Upvotes: 0

Views: 5849

Answers (2)

Anil
Anil

Reputation: 1

I guess by now you might have figured it out, in case not... below is the info... the way you get the data from excel, same way you can write to excel sheet.

To write to excel sheet... Excel.Cells(row, column) = "value"

at the end of the script, just before you you quit from excel, make sure u write the below line to save the data Excel.ActiveWorkbook.Save

Hope this helps...

Upvotes: 0

AutomatedChaos
AutomatedChaos

Reputation: 7500

Depends on how you have created your interfacing to Excel. If you use the Excel COM object (like Set objExcel = CreateObject("Excel.Application")) than it is certainly possible:
See some basic scripts at ActiveExperts.com if you need examples.

I have some bad experience with datatables in QTP (but I may be biased), that is why I do not use them. I do not know if two way communication with Excel is possible in QTP with the use of the build in datatables.


EDIT
See the QTP Help file how to do this with the build in datatables. It clearly says:

ExportSheet Method
Description
Exports a specified sheet of the run-time Data Table to the specified file.

If the specified file does not exist, a new file is created and the specified sheet is saved.
If the current file exists, but the file does not contain a sheet with the specified sheet name, the sheet is inserted as the last sheet of the file.
If the current file exists and the file contains the specified sheet, the exported sheet overwrites the existing sheet.

Syntax
DataTable.ExportSheet(FileName, DTSheet)

Argument    Type      Description 
FileName    String    The full file system path of the Excel table 
                      to which you want to export a sheet.  
DTSheet     Variant   The name or index of the run-time Data Table sheet
                      that you want to export. Index values begin with 1.  

Example
The following example uses the ExportSheet method to save the first sheet of the run-time Data Table to the name.xls file.

DataTable.ExportSheet "C:\name.xls" ,1

Upvotes: 1

Related Questions