By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,831 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,831 IT Pros & Developers. It's quick & easy.

Broken examples

P: n/a

I'm only talking about IPC related.
I have googled, yahooed, and so forth for several months now. ALL
examples I've come across have failed including those pertinent in the
Python doc area.

Outline:
cd somedir
ls -1 *.xls >thislist #ls hyphen one
python process.py
(yes - ls can go here if wanted. easier to edit outside)
open thislist
loop until done
start excel (or scalc)
have it open file
have it save file as a .csv (or .dbf)
close excell (or scalc)

Would seem to be a trivial exercise.
Starting Excel or any other executable in system path works fine.
popen3 opens whatever and reports no errors. r,w,and e all check as
being created.

r,w,e= os.popen3('ls -l')
print r.read() # works as expected

ALL attempts to send instructions to Excel or scalc FAIL COMPLETELY.
Actually, any attempt to communicate with a 'Point'n'Click' program
fails without errors being cited. They don't use redirectable command
line interfaces (like piping between programs) do they? :)

Trying to use the examples I have found that supposedly setup IPC's of
one type or another have all failed with errors that point to things
that make no sense in the first place.

Before you post a code example or a link to one be kind enough to run it
yourself first. You may get a surprise. The OOo examples do not work.
Not even when switching my system to their version. One problem they
have is asking a general user to change to places the user has no place
being and then to work there without permissions. I guess somebody
insists on doing all their work with root clearance down in the middle
of the vendor's tree. I don't think that's a healthy way to do things,
do you?

In OOo in particular, using their version of VBA one can create the
macro and even port it to python. If one found the correct Microsoft
suite docs I suspect that same could be done there too. But that doesn't
activate it from a python control. As for setting the macro to run at
startup, well... maybe I had other uses in mind today???? Besides the
moment I change it, coworker in other room is going to decide to... :)

Let's stick to Microsoft Office and OpenSource products for now. My
final goal will require specific conversations with a commercial vendor.
I would like those spread sheets working though.
Thanks

Steve
no******@hughes.net
Jul 24 '08 #1
Share this Question
Share on Google+
4 Replies

P: n/a
In message <ma************************************@python.org >, norseman
wrote:
The OOo examples do not work.
I have done OOo scripting in Python. What exactly does not work?
Jul 24 '08 #2

P: n/a

Lawrence D'Oliveiro wrote:
In message <ma************************************@python.org >, norseman
wrote:
>The OOo examples do not work.

I have done OOo scripting in Python. What exactly does not work?
--
http://mail.python.org/mailman/listinfo/python-list
=======================
file: z.scr
----------
#!/bin/bash

cd /opt/openoffice.org2.0/program

soffice "-accept=socket,host=localhost,port=2002;urp;" &
sleep 9

../python ./zhw.py

echo "Did this Run?"
# end of file
---------

file: zhw.py
---------
import uno

# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()

# create the UnoUrlResolver
resolver =
localContext.ServiceManager.createInstanceWithCont ext("com.sun.star.b
ridge.UnoUrlResolver", localContext )

# connect to the running office
ctx =
resolver.resolve("uno:socket,host=localhost,port=2 002;urp;StarOffice.Compo
nentContext" )
smgr = ctx.ServiceManager

# get the central desktop object
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)

# access the current writer document
model = desktop.getCurrentComponent()

# access the document's text property
text = model.Text

# create a cursor
cursor = text.createTextCursor()

# insert the text into the document
text.insertString( cursor, "Hello World", 0 )

# Do a nasty thing before exiting the python process. In case the
# last call is a oneway call (e.g. see idl-spec of insertString),
# it must be forced out of the remote-bridge caches before python
# exits the process. Otherwise, the oneway call may or may not reach
# the target object.
# I do this here by calling a cheap synchronous call (getPropertyValue).
ctx.ServiceManager
# end of file
------------

file: results
-----------
SysOp(P):sh z.scr
Traceback (most recent call last):
File "./zhw.py", line 20, in ?
text = model.Text
AttributeError: Text
Did this Run?
SysOp(P):=============NO!!!!!!
-----------------------

Haven't found any specific to scalc.
The zhw contents is closest to working I have found to date.
The z script was used to get to stated place and minimize typos.
As results shows - I ran as root. As user it screams lots. (Permissions)

The above is best effort so far. Others before it were even worse.

If you have working code I would like to tryout your linkage (process).
Before you send anything, can you use python to have scalc open a .xls
and save it as a csv? I can get python to have scalc open a specific
file and then point'n'click myself, but that isn't productive. I cannot
get scalc to do a saveas instruction issued by a python program. I have
no intentions of staying up all night pointing and clicking. Humans
think, computers do the repetitive. Yes? Besides, it is far easier to
train the computer than to train the ..... :)
Any help is appreciated.

Steve
no******@hughes.net

Jul 24 '08 #3

P: n/a
In message <ma************************************@python.org >, norseman
wrote:
Lawrence D'Oliveiro wrote:
>In message <ma************************************@python.org >, norseman
wrote:
>>The OOo examples do not work.

I have done OOo scripting in Python. What exactly does not work?

soffice "-accept=socket,host=localhost,port=2002;urp;" &
sleep 9

./python ./zhw.py
I've never tried that. I've run Python scripts from the "Tools/Macros/Run
Macro..." dialog.
Jul 25 '08 #4

P: n/a
norseman <no******@hughes.netwrote:
>
I'm only talking about IPC related.
I have googled, yahooed, and so forth for several months now. ALL
examples I've come across have failed including those pertinent in the
Python doc area.

Outline:
cd somedir
ls -1 *.xls >thislist #ls hyphen one
python process.py
(yes - ls can go here if wanted. easier to edit outside)
open thislist
loop until done
start excel (or scalc)
have it open file
have it save file as a .csv (or .dbf)
close excell (or scalc)

Would seem to be a trivial exercise.
Excel is a COM-driven application. You have to drive it through the object
model.

import win32com.client
excel = win32com.client.Dispatch( 'Excel.Application' )
xlCSV = 6
...
for nm in list_of_file_names:
csv = os.path.splitext( nm )[0] + '.csv'
wb = excel.Workbooks.Open( nm )
wb.SaveAs( csv, xlCSV )
wb.Close()

If you want to watch the progress, add "excel.Visible=1" after the
dispatch.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 25 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.