Thursday 13 March 2014

VBScript For Write& Read in Open Office Calc.

Hi Automation Testers,

Generally most of the companies use Excel as the preferred spreadsheet & most of us are well versed in using Excel through VBScripting & QTP. But then there are few organizations which may prefer to use the open source Open Office Calc for their QTP automation support. I tried to get the know how from the web but could not get it. Tried myself couple of times & developed the below script which is able to read & write into Open Office Calc.

Hope you would benefit from this script...



'smo=service manager object
'od=desktop object
'doo=document object
'so=sheet object
'co=cell object'

Set smo = CreateObject("com.sun.star.ServiceManager")  'To open the Sun Server

Set od= smo.createInstance("com.sun.star.frame.Desktop")  'To open the Desktop 
Set doo = od.loadComponentFromURL("file:///C:\data12.ods", "_blank", 0, array()) 'To open the document
Set so = doo.Sheets.getByName("Sheet4") ' To get the particular sheet   

so.getCellByPosition( 0, 0 ).setString( "Hai" ) 'To Write the String  

so.getCellByPosition( 1, 0 ).setString("Shiva") 
so.getCellByPosition( 2, 0 ).setString("Kumar") 
so.getcellbyposition(3,0).setstring("Polineni")
so.getcellbyposition(0,1).setvalue(90106) 'To Write the Value  so.getcellbyposition(0,2).setstring("Testing")


Note:= Generally in While writing the VBScript for Excel we can write data in sheetobject.cells(row num,column num) But here Sheetobject.getcellbyposotion(column num,row num)

Note2:= And also in Excel row number and Column number starts with 1 onwards, Like sheetobject.cells(1,1)
But In Open Office VBScript Column number and row number starts from 0 onwards like Sheetobject.getcellbyposotion(0,0)

No comments:

Post a Comment