Win32com, and Excel issues.

kyosohma at gmail.com kyosohma at gmail.com
Wed Apr 18 09:06:46 EDT 2007


On Apr 18, 2:38 am, Ant <ant... at gmail.com> wrote:
> Hi all,
>
> I'm doing some Excel automation work for a friend, and am developing
> on a machine running Office 2000. My friends machine is running Excel
> 2003. The code I've written works like a charm on my machine (in fact
> all three of my machines), but falls over early on on Excel 2003.
>
> The code snippet it falls over on is code to copy one worksheet after
> another:
>
> app = wincl.Dispatch("Excel.Application")
> app.Visible = True
> app.Workbooks.Open(self.filename)
> sheet = app.Worksheets(1)
> sheet.Copy(None, sheet)
>
> and this last line throws the following exception:
>
> pywintypes.com_error: (-2147417851, 'the server threw an exception.'
> , None, None)
>
> which isn't too helpful.
>
> I'm wondering if something has changed in the Excel API that doesn't
> allow a null parameter to Copy or some similar issue. I tried using
> the keyword argument format, but that simply refused to work.
>
> Other relevant information:
>
> * The program is packaged using py2exe, so I know that the same
> version of Python, and the same libraries are on each machine.
> * One of the test machines running Excel 2000 does not have Python
> installed.
> * The machines are all of a similar spec.
>
> Any ideas are welcome!

I can't find anything about copying a worksheet, but I found a some
fairly detailed information about COM objects and getting more
information about Python's bindings to them here:
http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html or here:
http://mathieu.fenniak.net/plotting-in-excel-through-pythoncom/

Hopefully this will give you some pointers.

Mike





More information about the Python-list mailing list