Ask Your Question
0

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
1

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
1

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

kelsa gravatar image

Hi,

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

edit flag offensive delete link more

Comments

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

Stats

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

Seen: 649 times

Last updated: Mar 06