473,466 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Broken examples


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
4 1767
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael | last post by:
I have broken PythonWin and I don't know how or why. It worked great until recently. I have installed / removed several apps since it worked last. I could have a virus unknown to my antivirus...
28
by: Grant Edwards | last post by:
I finally figured out why one of my apps sometimes fails under Win32 when it always works fine under Linux: Under Win32, the pickle module only works with a subset of floating point values. In...
5
by: Retlak | last post by:
A week ago I decided to convert an old web site from frames to a frameless layout. I'd done this before with a different website, converted from layout using frames to layout using tables....
42
by: cody | last post by:
public DateTime Value { get { try { return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text)); } catch (FormatException)
2
by: jm | last post by:
Hello, It appears the compiler #define _MSC_VER is broken under .NET, even though when "mousing over" the _MSC_VER it says it's #def'd as 1300. That's exactly what I'd expect. However, when I...
5
by: clintonG | last post by:
Neither MSDN code examples nor will function. Has anybody figured out how to use the 2.0 classes, methods and properties to dynamically create HTML in the HTML <head> element? I've burned...
13
by: Steven Bethard | last post by:
Jean-Paul Calderone <exarkun@divmod.comwrote: Interesting. Could you give a few illustrations of this? (I didn't run into the same problem at all, so I'm curious.) Steve
0
by: Terry Reedy | last post by:
norseman wrote:
8
by: Steven D'Aprano | last post by:
According to the Python docs, once an iterator raises StopIteration, it should continue to raise StopIteration forever. Iterators that fail to behave in this fashion are deemed to be "broken": ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.