Wednesday, September 1, 2010

VBS and OpenOffice

Here's a quick piece of code that opens an OpenOffice Calc spreadsheet, writes text to a cell, and makes that text bold.

Set objServiceManager = CreateObject("")
Set objDesktop = objServiceManager.createInstance("")
Set objCalcDoc = objDesktop.loadComponentFromURL("file:///C:/file.ods", "_blank", 0, Array())
Set objSheet = objCalcDoc.getSheets().getByIndex(0)
objSheet.getCellByPosition(0, 0).SetString("Henrik Falk")
objSheet.getCellByPosition(0, 0).charWeight = 150

If you want to open a new spreadsheet, use this code instead:
Set objCalcDoc = objDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, Array())

No comments: