Micro Focus QTP (UFT) Forums
Add a row to a datatable - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Add a row to a datatable (/Thread-Add-a-row-to-a-datatable)



Add a row to a datatable - ConstantChange - 01-12-2009

Hi!

I need to create a performance log while running qtp tests, and I want to write the results out to an excel sheet.

Now, there does not seem to be an obvious way to create a row in excel. Even more so, using datatable.nextRow will jump to the freaking first row, and what makes it even worse is that if I used a pre-prepared sheet with dummy values in it, "lastRow" will take me to the last row of those dummy values (obviously), so before each write to the excel I would need to actually search for the first entry which is a dummy value, before I could write to the sheet.

Can somebody please help me out!? (Or if there is no way of adding a row let me know the adress of the guy who designed that freaking qtp object model?)

Thanks alot!

Cheers,
CC


RE: Add a row to a datatable - Ankur - 01-12-2009

Quote:(Or if there is no way of adding a row let me know the adress of the guy who designed that freaking qtp object model?)

LOL Smile

ok, this has to do with excel automation model rather than QTP's automation model. You can write a custom function that opens an external excel workbook , opens a sheet in it and then add the required message in the required cell.

I am providing a function, i wrote sometime back for a similar requirement...hope it will help you get started. You can improvise upon it as per your needs.

Code:
Function PutValueInFile (sfilePath, msg, irow, icolumn,isheet)
   sfilePath = "C:\Test.xls"
   Set ExcelObj = CreateObject("Excel.Application")
   ExcelObj.Workbooks.Open sfilePath
   Set NewSheet = ExcelObj.Sheets.Item(isheet)
   NewSheet.Cells(irow,icolumn) = msg
   ExcelObj.ActiveWorkbook.Save
   ExcelObj.Application.Quit
   Set ExcelObj = Nothing
End Function



RE: Add a row to a datatable - ConstantChange - 01-12-2009

Yeah!

Smile
Thanks so much mate!

I think the QTP people should forget about their internal libraries and instead promote only using that excel object model..

I assume I might be able to format result-sheets with that as well???


THanks again!

Cheers!