[python-win32] Python and Excel via Cron
Jd H
pyth_ora at yahoo.com
Thu Nov 22 00:40:25 CET 2007
I included an additional backslash and still same
error type below:
Traceback (most recent call last):
File "c:\Python24\test.py", line 4, in ?
myExcel.Workbooks.Add('C:\\Python24\\test.xls')
File
"C:\Python24\Lib\site-packages\win32com\client\dynamic.py",
line 496, in __getattr__
raise AttributeError, "%s.%s" % (self._username_,
attr)
AttributeError: Excel.Application.Workbooks
I have other processes running on a daily/ minute
basis and they run via cron. So I don't think it is a
permission issue. Excel is running (several instances
for each failure).
--- Larry Bates <larry.bates at websafe.com> wrote:
> Why are you using Cygwin cron instead of native
> Windows Task Scheduler (Windows
> version of cron-like scheduler)?
>
> These lines:
>
> > myExcel.Workbooks.Add('C:\Python24\\test.xls')
> > myExcel.Workbooks.Add('C:\Python24\\macro.XLA')
>
> >
>
myExcel.ActiveWorkbook.SaveAs('C:\Python24\\test.xls')
>
> should read:
>
> > myExcel.Workbooks.Add('C:\\Python24\\test.xls')
> > myExcel.Workbooks.Add('C:\\Python24\\macro.XLA')
>
> >
>
myExcel.ActiveWorkbook.SaveAs('C:\\Python24\\test.xls')
>
> -Larry
>
>
> 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')
> > 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:
> >
> > Traceback (most recent call last):
> > File "c:\Python24\test.py", line 4, in ?
> > myExcel.Workbooks.Add('C:\Python24\\test.xls')
> > File
>
"C:\Python24\Lib\site-packages\win32com\client\dynamic.py",
> line
> > 496, in __getattr__
> > raise AttributeError, "%s.%s" %
> (self._username_, attr)
> > AttributeError: Excel.Application.Workbooks
> > Thanks,
> > JD
> >
> > */Tim Roberts <timr at probo.com>/* wrote:
> >
> > Jd H wrote:
> > > Hello,
> > >
> > > I have the below python code which opens an
> excel sheet, runs a macro
> > > then save the file. When run from python it
> runs perfectly. Code is
> > > below. File name is test.py
> > >
> > > <<<
> > > from win32com.client import Dispatch
> > > ;
> > > myExcel = Dispatch('Excel.Application')
> > > myExcel.Visible = 1
> > >
> myExcel.Workbooks.Add('C:\Python24\test.xls')
> >
> > I don't believe this ever ran correctly as you
> have posted it. This
> > will not open a file called "test.xls" in the
> directory "Python24".
> > Instead, this will open a file in the root
> called "Python24est.xls"
> > with a tab character in the name. You HAVE to
> be careful about
> > backslashes in Python. Either double the
> backslashes, replace them with
> > forward slashes, or use a raw string (
> r'c:\Python24\test.xls' ).
> >
> > >
> myExcel.Workbooks.Add('C:\Python24\macro.XLA')
> > > myExcel.Run('Macro1')
> > > myExcel.Application.DisplayAlerts = False
> > >
>
myExcel.ActiveWorkbook.SaveAs('C:\Python24\test.xls')
> > > myExcel.Quit()
> > > >>>
> > >
> > > When run from cron, it fails at line 3 when
> it opens the file with
> > > below message:
> > >
> > > Traceback (most recent call last):
> > > File "c :\Python24\test.py", line 20, in ?
> > > jd.Workbooks.Add('C:\Python24\test.xls')
> > > File
>
"C:\Python24\Lib\site-packages\win32com\client\dynamic.py",
> > > line 496, in __getattr__
> > > raise AttributeError, "%s.%s" %
> (self._username_, attr)
> > > AttributeError: Excel.Application.Workbooks
> > >
> > > Any ideas how to resolve this?
> >
> > What utility are you using to schedule this?
> Are you actually using
> > Cygwin's cron, or the "at" command, or the
> standard "Schedule Tasks"
> > thing, or what? What operating system are you
> using?
> >
> > Most of the task scheduler tools run as a
> service. By default, a
> > service cannot launch a GUI application. Also,
> in some cases, the
> > services run as a user that has restricted
> rights. Tell us a little
> > more about how you are doing this, and perhaps
> we can suggest how to
> > accomplish it.
> >
> > --
> > Tim Roberts, timr at probo.com
> > Providenza & Boekelheide, Inc.
> >
> > _______________________________
> ________________
> > python-win32 mailing list
> > python-win32 at python.org
> >
> http://mail.python.org/mailman/listinfo/python-win32
> >
> >
> >
>
------------------------------------------------------------------------
> > Be a better sports nut! Let your teams follow you
> with Yahoo Mobile. Try
> > it now.
> >
>
<http://us.rd.yahoo.com/evt=51731/*http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ
>
> > >
> >
> >
> >
>
------------------------------------------------------------------------
> >
> > _______________________________________________
> > python-win32 mailing list
> > python-win32 at python.org
> >
> http://mail.python.org/mailman/listinfo/python-win32
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
____________________________________________________________________________________
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs
More information about the python-win32
mailing list