Thanks,
Ken
Gary Herron
Aside from what has already been said, it might be nice for you to
read my article about OOo and Python at
http://www.stuvel.eu/ooo-python ;-)
Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
Hi, Sybren. I tried folloing your recipe on Windows with OOo 2.0 ...
Minor problem: the executable is called soffice, not ooffice.
Major problem: it crashed right at the start, somewhere in the maze of
dlls.
The following interactive session reproduces the problem:
| C:\Program Files\OpenOffice.org
2.0\program\python-core-2.3.4\bin>python
# OOo includes a complete python distribution. Note the directory name
says 2.3.4 ...
| Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)]
on win32
... but the program identifies itself as 2.3.5
| Type "help", "copyright", "credits" or "license" for more
information.
| >>> import sys
| >>> sys.path.append(r'C:\Program Files\OpenOffice.org 2.0\program')
# The above directory contains all the dlls plus a handful of python
files
| >>> import pyuno # from pyuno.dll; there's no other pyuno.*
| >>> _g_ctx = pyuno.getComponentContext()
# crash
Has anyone managed to get further than this on Windows (XP Pro, SP 2)?
Cheers,
John
That's not nice.
> Has anyone managed to get further than this on Windows (XP Pro, SP
> 2)?
Not me - I'm not using Windows. If anyone knows more about this,
please post here or post a comment at
http://www.stuvel.eu/archive/31/article-about-openofficeorg-and-python
so that I can improve the article.
Is there any OO compiled with P2.4x for Windows somewhere ?
It seems that there is only one person to maintain the Python interface
and that there few users - no critical mass. I hope that this will
change as OpenOffice is, with the exception of the Base component, a
solid package. The base (database) component is evolving.
Colin W.
> I've done some small things with Python/OpenOffice, using Windows XP.
> They appear to work OK.
As you might have noticed from my earlier post, I can't get off the
ground. Can you please give an example (with code) of a "small thing"
that works OK?
TIA,
John
Here is something that works for me under XPsp2 to either save a doc or
save it as PDF:
filepath = argv[0]
exportpdf = argv[1]
ctxLocal = uno.getComponentContext()
smgrLocal = ctxLocal.ServiceManager
resolver =
smgrLocal.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",ctxLocal)
url =
"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
ctx = resolver.resolve(url)
smgr = ctx.ServiceManager
desktop =
smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx)
properties = []
if exportpdf == "yes":
p = PropertyValue()
p.Name = "Hidden"
p.Value = True
properties.append(p)
properties = tuple(properties)
doc = desktop.loadComponentFromURL("file:///c:"+filepath+".odt" ,
"_blank", 0, properties)
if exportpdf == "yes":
properties = []
p = PropertyValue()
p.Name = "Overwrite"
p.Value = True
properties.append(p)
p = PropertyValue()
p.Name = "FilterName"
p.Value = 'writer_pdf_Export'
properties.append(p)
properties = tuple(properties)
doc.storeToURL("file:///c:"+filepath+".pdf", properties)
else:
doc.store()
doc.dispose()
You must start OO this way first:
cd C:\Program Files\OpenOffice.org 2.0\program
soffice "-accept=socket,host=localhost,port=2002;urp;"
import uno, sys, socket
from com.sun.star.beans import PropertyValue
... and your start_oo_server.bat file with:
@SET PYTHONPATH=C:\Program Files\OpenOffice.org 2.0\program;C:\Program
Files\OpenOffice.org 2.0\program\python-core-2.3.4\lib
@SET PATH=C:\Program Files\OpenOffice.org 2.0\program;C:\Program
Files\OpenOffice.org 2.0\program\python-core-2.3.4\bin
Many thanks for all that, olive; I made the minimal hacks to make it
open an XLS ffile, and it worked!
I'll try to see why that worked and my previous experiment crashed
inside a DLL.
Cheers,
John
Thanks, keep us posted!