We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

python script connect to writer document

asked 2019-01-17 23:34:23 +0200

carnish gravatar image

Using python and uno I want to connect to an open document and, for example, save it.

The following code connects to libreoffice, but I don't know how to connect to the file I have open in writer. Anyone know what comes next?

import uno
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
            "com.sun.star.bridge.UnoUrlResolver", localContext )

# connect to the running office
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2019-03-06 14:16:13 +0200

updated 2019-03-06 14:17:22 +0200

Hi carnish

Designing & Developing Python Applications wiki page may help you getting acquainted with Python script principles and tools. You can equally refer to LibreOffice Python Scripts Help (work in progress) whose content is not limited to 6.3 release.

To discover more you may be bound to translate existing Basic examples to Python, to explore LibreOffice API or run Python interpreter. Note that Apache OpenOffice Python wiki provides plenty of information that's applicable to LibreOffice too.

Happy Python!

edit flag offensive delete link more

answered 2019-01-18 00:09:49 +0200

kelsa gravatar image


use this as starting point https://github.com/kelsa-pi/PyUNO_Wor...

edit flag offensive delete link more


This post may also be of help -> Python IDE Basics

Ratslinger gravatar imageRatslinger ( 2019-01-23 18:25:16 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-01-17 23:34:23 +0200

Seen: 2,595 times

Last updated: Mar 06 '19