Thursday, July 26, 2012

Inserting Excel formula into QTP Datatable

As we know we can write formula's using vb script directly in to excel, but here I am trying to insert excel formula's in datatable. Usually we use datatable to ease our scripting but inserting excel formula's will throw error on exporing the datatable, Let us consider the following script

datatable.Value("A",2) = "2"
datatable.SetCurrentRow(2)
datatable.Value("A",2) = "3"
datatable.SetCurrentRow(3)
datatable.Value("A",2) = "=(A2+A3)"
datatable.SetCurrentRow(4)
datatable.Value("A",2) = "=HYPERLINK(""C:\Documents and Settings\1419084\My Documents\IP_Config.bmp""|""Click to see Image"")"
datatable.ExportSheet "C:\Documents and Settings\1419084\Desktop\FI_Overview\2.xls","Action1"


In above script I'm trying to insert two formula's one is addition and other is hyperlink. While running the script throws following error on datatable export.

Though the formula is captured on datatable but it's throwing error, after stopping the run we can able to see the datatable with formula in results. Despite it throws general error while exporting the datatable.
Here I'm inserting single quote(') before the formula to handle this problem, after executing the test open the Excel and remove the single quote(') using format painter to recover the formula. This method reduced a lot of time for me while capturing screen shots.


No comments:

Post a Comment