[python-win32] Python and Excel via Cron
Tim Roberts
timr at probo.com
Thu Nov 22 00:24:56 CET 2007
Jd H wrote:
> I am posting test.py again below:
>
> <<<
> from win32com.client import Dispatch
>
> myExcel = Dispatch('Excel.Application')
> myExcel.Workbooks.Add('C:\Python24\\test.xls')
> myExcel.Workbooks.Add('C:\Python24\\macro.XLA')
That's still not right. It will work this time, until some Python
upgrade where \p becomes a valid escape sequence. Seriously, any time
you write a path in Python in Windows, you need to either:
* Double ALL of the backslashes
* Use forward slashes, or
* Use raw strings
Make it habit, every time, and you will avoid bugs.
> myExcel.Run('Macro1')
> myExcel.Application.DisplayAlerts = False
> myExcel.ActiveWorkbook.SaveAs('C:\Python24\\test.xls')
> myExcel.Quit()
> >>>
>
> Cygwin cron calling test.py works great on my Windows XP PC with
> Python 2.4 version. From windows 2000 terminal server with same Python
> 2.4 version, it works perfectly as it is supposed to if run via Python
> 2.4. But if called via cygwin cron (like it needs to be), it fails per
> below error:
> ...
> AttributeError: Excel.Application.Workbooks
Are you starting cron in your Terminal Server session and then
disconnecting, hoping that it keeps running? Or are you launching cron
from the server's console?
A disconnected Terminal Server session doesn't have a desktop. GUI
applications can't run without a desktop. Also Terminal Server has a
lot of complicated security options; is your username allowed to run
applications at the console?
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list