TableOfContents(2)

OpenOffice and Python

Start openoffice

openoffice -accept="socket,host=localhost,port=2002;urp;"

Connect to OpenOffice

python

import uno

local = uno.getComponentContext()

resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)

context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")

Modify Content

Load Services

desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)

document = desktop.getCurrentComponent()

set cursor

cursor = document.Text.createTextCursor()

Modifying text

document.Text.insertString(cursor, "This text is being added to openoffice using python and uno package.", 0)

==== Line breaks ===

document.Text.insertString(cursor, "\n\nThis is a new paragraph.", 0)