[python-win32] testMSOffice.py and Excel 2003

Cavanagh, Mike mike.cavanagh at siemens.com
Mon Sep 26 20:47:13 CEST 2005


Here we go:

Worked with Excel 2000, but not 2003:
lastRow = xlSheet.Cells.Find('Hello World',xlSheet.Cells(1, 1), 1, 1).Row

Works with Excel 2000 and 2003:
lastRow = xlSheet.Cells.Find('Hello World',xlSheet.Cells(1, 1), -4163,
1).Row

>From MSDN:
expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection,
MatchCase, MatchByte)

Excel 2003 wanted the xlValues constant (-4163) for LookIn, 2000 was happy
with 1.  Not sure why...

Cheers,

Mike



-----Original Message-----
From: Cavanagh, Mike 
Sent: Friday, September 23, 2005 9:23 AM
To: python-win32 at python.org
Subject: Re: [python-win32] testMSOffice.py and Excel 2003


Tim,

Thanks for the reply, the test case now passes.

However, our internal application is still failing.

code snippet:

import win32com
import win32com.client.dynamic
import pythoncom
from pywintypes import Unicode
from win32com.client import gencache

xl = win32com.client.dynamic.Dispatch("Excel.Application")
xl.Visible = 1
xlBook = xl.Workbooks.Open('C:\\test.xls')
xlSheet = xlBook.Worksheets(1)
print xlSheet.Name
xlSheet.Cells(1,1).Value = "Hello World"
print xlSheet.Cells(1,1).Value

lastCol = 14
lastRow = xlSheet.Cells.Find('Hello World',xlSheet.Cells(1, 1), 1, 1).Row
data = xlSheet.Range(xlSheet.Cells(1,1),
xlSheet.Cells(lastRow,lastCol)).Value

xl.Workbooks(1).Close(SaveChanges = 1)
xl.Quit()

/snippet

When this is run, I receive the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "c:\python24\lib\site-packages\win32com\test\testExcel.py", line 16,
in ?

    lastRow = xlSheet.Cells.Find('Hello World',xlSheet.Cells(1, 1), 1,
1).Row
  File
"c:\python24\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-00
0000000046x0x1x5\Range.py", line 197, in Find
    , MatchCase, MatchByte, SearchFormat)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None,
None,
 0, -2147352565), None)

I believe this error is coming from Excel, but I am not sure why.

The offending line works with Excel 2000 but not 2003.

Thanks,

Mike

-----Original Message-----
From: Tim Roberts [mailto:timr at probo.com]
Sent: Friday, September 16, 2005 3:17 PM
To: python-win32 at python.org
Subject: [python-win32] testMSOffice.py and Excel 2003


On Thu, 15 Sep 2005 15:24:52 -0400, "Cavanagh, Mike" 
<mike.cavanagh at siemens.com> wrote:

>We have a couple of internal applications that are written in Python and
>have always worked with Excel 2000.
>
>We are 'upgrading' to Excel 2003 and in my pre-rollout testing, our
>applications are failing.
>
>Using the testMSOffice.py test case, I receive the following:
>  
>
...

>  File "C:\Python24\Lib\site-packages\win32com\test\testMSOffice.py", line
>96, in TextExcel
>    xl.Workbooks().Add()
>  File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
165,
>in __call__
>    return
>self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.
>defaultDispatchName,None)
>com_error: (-2147352562, 'Invalid number of parameters.', None, None)
>
>I'm beginning to pull my hair out here, any help would be appreciated.
>

Remove the inner set of parentheses:
    xl.Workbooks.Add()

Workbooks is a collection object, not a method.

-- 
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
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32


More information about the Python-win32 mailing list