Home » Uncategorized » Use Open Office Calc in QTP

Use Open Office Calc in QTP

Open Office in QTP would be one time setup in your Framework and this can reduce the cost of the project as Open Office is freeware and Ms Excel is not

Lets Discuss how

The Easy Way – Using QTP

systemutil.Run “C:\Program Files\OpenOffice.org 3\program\scalc.exe”

systemutil.Run “C:\Documents and Settings\qtpserver\Desktop\Test_Case.xls”
You have Opened the Open Office Calc file , now how to read data from cells or how to write data on cells

For this we need to Invoke Open Office from its core services 

How to

‘ Create Object of Service Manager
‘Open Task Manager and note the no. of Processes navigating to Processes Tab, now write the below mentioned line in VBS file and double click VBS file and check the Proccesses in Task manager must have increased

Set object_Service_Manager= WScript.CreateObject(“com.sun.star.ServiceManager”)

‘ Create the Desktop Object

Set object_Desktop= object_Service_Manager.createInstance(“com.sun.star.frame.Desktop”)

‘This will open a New open office calc file

Dim args()
Set object_Document= object_Desktop.loadComponentFromURL(“private:factory/scalc”, “_blank”, 0, args)

‘If you want to open any file from your computer , assign the path of the file in the variable and use that variable

cURL = “file:///C:\Documents and Settings\qtpserver\Desktop\test_case.ods”

Set object_Document= object_Desktop.loadComponentFromURL(cURL, “_blank”, 0, args)

‘Copy above statments in VBS file and double click , this will open calc application in your system

‘Reading value from cell

‘First get the Sheet of the File by name, Lets suppose we want to read from Sheet2

set object_Sheet = object_Document.getSheets().getByName( “Sheet2” )

‘Now create cell object and get the value of the cell by position , get the value of the first row and first column and print

set object_Cell = object_Sheet.getCellByPosition( 1,1 )
cell_Value = object_Cell.getValue()
msgbox cell_Value

‘Set the value to any cell by position

temp_val = 10
object_Cell.setValue(temp_val)

 

Queries

Mail to deepsatyawali@gmail.com

 

6 thoughts on “Use Open Office Calc in QTP

  1. Hi Deep,

    Thanks for the useful post above. But, I’m a little confused with the implementation. My confusion is that what part of code has to go inside .vbs and what part of code needs to used in qtp for reading and writing into a open office file. Request you to please update me. Thanks.

  2. How can the second line be executed? I mean systemutil.Run “C:\Documents and Settings\qtpserver\Desktop\Test_Case.xls” line cannot open the .xls file and will throw an error because for opening .xls file in qtp you need to create an excel object first and if you dont have excel in your system, it wont be possible. I tried your inputs in my code, its not working.

Leave a comment