Writing data to an Excel file without importing the data to the data table
This function will allow you to set data in an external Excel file (specifying the sheet and the cell), without importing the file to the QuickTest data table. The function uses automation objects to create an Excel object.
This function is not part of QuickTest Professional. It is not guaranteed to work and is not supported by Hewlett-Packard Support. You are responsible for any and all modifications that may be required.
PutValueInFile (sfilePath, isheet, irow, icolumn, value)
sfilePath | The path and name of the Excel file. |
isheet | The sheet of the Excel file. This can be an index number or the sheet name. |
irow | The row number in the table. |
icolumn | The column number in the table. |
value | The value to put within the defined cell in the specified sheet. |
Function PutValueInFile (sfilePath, isheet, irow, icolumn, value)
Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.Workbooks.Open sfilePath
Set NewSheet = ExcelObj.Sheets.Item(isheet)
NewSheet.Cells(irow,icolumn) = value
ExcelObj.ActiveWorkbook.Save
ExcelObj.Application.Quit
Set ExcelObj = Nothing
End Function
Example:
filename = "D:\temp\Test.xls"
PutValueInFile filename,1,2,2,"Hello From QTP!"