Micro Focus QTP (UFT) Forums
simple excel automation - 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: simple excel automation (/Thread-simple-excel-automation)



simple excel automation - excellentpawan - 07-06-2013

I wrote following code for a task
task: There are two column A and B, these are parameterized with some values in data table. Using this values with calculator I want to calculate WOR and type output in excel's row(1,1) for first iteration and next value in cell(2,1) for second iteration. Please help

Code:
Set oexcel = createobject("Excel.Application")  'to create excel
oexcel.Visible = true
oexcel.Workbooks.Add

If not  Window("Calculator").Exist(1) Then
systemutil.Run ("C:\WINDOWS\system32\calc.exe")
End If
Window("Calculator").WinEdit("Edit").Type DataTable("A", dtGlobalSheet)
Window("Calculator").WinButton("/").Click
Window("Calculator").WinEdit("Edit").Type DataTable("B", dtGlobalSheet)
Window("Calculator").WinButton("=").Click
WOR = window("Calculator").WinEdit("Edit").GetROProperty("text")
Window("Calculator").WinButton("C").Click
oexcel.Workbooks.cells(1,1).value = WOR



RE: simple excel automation - Ankur - 07-06-2013

Check this -

Code:
iRow = DataTable.GetCurrentRow 'Get the current row count from DataTable
Set oexcel = createobject("Excel.Application")  'to create excel
oexcel.Visible = true
oexcel.Workbooks.Add
Set objSheet1 = oexcel.Sheets("Sheet1")

If not  Window("Calculator").Exist(1) Then
systemutil.Run ("C:\WINDOWS\system32\calc.exe")
End If
Window("Calculator").WinEdit("Edit").Type DataTable("A", dtGlobalSheet)
Window("Calculator").WinButton("*").Click
Window("Calculator").WinEdit("Edit").Type DataTable("B", dtGlobalSheet)
Window("Calculator").WinButton("=").Click
WOR = window("Calculator").WinEdit("Edit").GetROProperty("text")
Window("Calculator").WinButton("C").Click
objSheet1.Cells(iRow,1).Value = WOR