[python-win32] Problem with COM and MsExcel

Brunain Christophe Christophe.Brunain@health.fgov.be
Wed, 2 Apr 2003 08:46:03 +0200


Hello all !

I begin tu use python win and the COM features

I try to do a little scripyt that takes a text file (an unload from a
database) and to put it in an excel worksheet

It works good, but only one time

the second time I execute the script, i only se the menubar and the =
toolbar
on the top of the screen, the document itself is not displaying

I see only what was my screen before the execution of the script

If i close all the excel sheets and look in the task manager, I see an
EXCEL.EXE still running

If i make an "end process" it works, but if i try to run the script =
once
again, it makes an error.

here is the script i use

import win32com.client

ex =3D win32com.client.Dispatch("Excel.Application")
ex.Visible =3D 1
ex.Workbooks.Open("C:\\test\\test.xls")
ex.Run("SaveText","C:\\test\\codes", "C:\\test\\codes2.xls")
ex.Quit

and the traceback i got when i close the excel.exe and run the script =
once
again

PythonWin 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on =
win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) - =
see
'Help/About PythonWin' for further copyright information.
Traceback (most recent call last):
  File
"C:\Python22\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py"=
,
line 307, in RunScript
    debugger.run(codeObject, __main__.__dict__, start_stepping=3D0)
  File =
"C:\Python22\lib\site-packages\Pythonwin\pywin\debugger\__init__.py",
line 60, in run
    _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File =
"C:\Python22\lib\site-packages\Pythonwin\pywin\debugger\debugger.py",
line 591, in run
    exec cmd in globals, locals
  File "C:\test\test1.py", line 4, in ?
    ex.Visible =3D 1
  File "C:\Python22\lib\site-packages\win32com\client\dynamic.py", line =
504,
in __setattr__
    raise AttributeError, "Property '%s.%s' can not be set." %
(self._username_, attr)
AttributeError: Property 'Excel.Application.Visible' can not be set.

Does someone know what's wrong ?
i've looked in the archives of this mailing list but i haven't found :(

Thanks a lot for your answers

PS :
Sorry if my english is not so good

Brunain Christophe
Service informatique de l'expertise m=E9dicale
SPF Sant=E9 Publique, S=E9curit=E9 de la chaine alimentaire et =
Environnement