Solved

Is it possible to run openoffice scripts from the command line?

Posted on 2010-11-24
1
588 Views
Last Modified: 2012-05-10
I installed the python uno libraries and am able to run the HelloWorld.py script from within Writer but I was wondering if it's possible to run these python scripts from the command line. I tried doing:
>python HelloWorld.py
but got no response or no error message. I figure that some code has to be added to connect with openoffice and tell it which document should be modified.
0
Comment
Question by:opike
1 Comment
 
LVL 2

Accepted Solution

by:
markoilic earned 500 total points
ID: 34206048
First  Open Office need to be started with following command:

x:\path_to_openOffince\program>soffice "-accept=socket,host=localhost,port=2002;urp;"

Then if you have installed uno package in python you can make conection with:

import uno
 
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
                        "com.sun.star.bridge.UnoUrlResolver", localContext )
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
model = desktop.getCurrentComponent()
text = model.Text
cursor = text.createTextCursor()
text.insertString( cursor, "Hello World from command line", 0 )
ctx.ServiceManager


More on following link
http://wiki.services.openoffice.org/wiki/PyUNO_bridge
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is about my first experience with programming Arduino.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now