Differences between revisions 2 and 3
Revision 2 as of 2008-08-19 15:12:14
Size: 726
Comment:
Revision 3 as of 2008-08-19 15:23:08
Size: 1452
Comment: load current document
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[TableOfContents(2)]]

= OpenOffice and Python =
== Start openoffice ==
Line 5: Line 9:
== Connect to OpenOffice ==
Line 18: Line 23:
 *Now access the UnoUrlResolver service. This will connect to OpenOffice.org program.  *Now access the UnoUrlResolver service. This will allow you to connect to OpenOffice.org program.
Line 22: Line 27:
 * Now you are connected and you can access OpenOffice via its API mechanism.  * Now load the context and you are now connected. You can access OpenOffice via its API mechanism.
Line 26: Line 31:

== Modify Content ==
=== Load Services ===
 *There is a service responsible for the current document which is called desktop. This service can be access by the name "com.sun.star.frame.Desktop".
 *We will be using that service so we need to create it/load it.
{{{
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
}}}
 *We now have access to the Desktop service. We now can load and manage documents.
 *To get the current document we call ''getCurrentComponent'' method:
{{{
document = desktop.getCurrentComponent()
}}}

TableOfContents(2)

OpenOffice and Python

Start openoffice

  • Start openoffice so it listens on a port.

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

Connect to OpenOffice

  • Open UNO. These are python bindings to openoffice api.
  • Start python:

python
  • Then import uno.

import uno
  • Now import the local component context.

local = uno.getComponentContext()
  • Now access the UnoUrlResolver service. This will allow you to connect to OpenOffice.org program.

resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
  • Now load the context and you are now connected. You can access OpenOffice via its API mechanism.

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

Modify Content

Load Services

  • There is a service responsible for the current document which is called desktop. This service can be access by the name "com.sun.star.frame.Desktop".
  • We will be using that service so we need to create it/load it.

desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
  • We now have access to the Desktop service. We now can load and manage documents.
  • To get the current document we call getCurrentComponent method:

document = desktop.getCurrentComponent()

MyWiki: OpenOffice (last edited 2009-10-01 00:40:58 by LukaszSzybalski)