I am using Python 2.2.3 with Pywin32-210.win32-py2.2 The following
Python sequence works fine when using the 'late binding' method.

import win32com.client.dynamic
import types
xlApp = win32com.client.Dispatch("Excel.Application")
xlBook = xlApp.Workbooks.Open( 'C:\\TestExcel.xls' )
sheet = xlBook.Worksheets( 1 )
sheet.Activate()
rangeToSort = xlApp.Range('a2:e5')
rangeToSort.Sort( Key1=sheet.Columns( 3 ), Order1=1 , Header=1 )

Since I required the use of the GetOffset function when using COM with
Excel, I compiled the Excel 11.0 Object Library using the COM MakePy
Utility in PythonWin. When I run the above sequence now, I get the
following error. If I then delete the generated Excel 11.0 .py file in
the win32com\gen_py directory. The sequence will then run without a
problem.

Traceback (most recent call last):
  File "C:\Python22\Tools\idle\Debugger.py", line 37, in run
    return apply(bdb.Bdb.run, (self,) + args)
  File "C:\Python22\lib\bdb.py", line 349, in run
    exec cmd in globals, locals
  File "<pyshell#10>", line 1, in ?
    rangeToSort.Sort( Key1=sheet.Columns( 3 ), Order1=1 , Header=1 )
  File
"C:\Python22\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-0
00000000046x0x1x5.py", line 22609, in Sort, SortMethod, DataOption1,
DataOption2, DataOption3)
  File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line
446, in _ApplyTypes_
    return self._get_good_object_( com_error: (-2147352567, 'Exception
occurred.', (0, 'Microsoft Office Excel', "The sort reference is not
valid. Make sure that it's within the data you want to sort, and the
first Sort By box isn't the same or blank.", 'C:\\Program
Files\\Microsoft Office\\OFFICE11\\1033\\xlmain11.chm', 0, -2146827284),
None)

Varying the setting of the 'bForDemand' parameter did not seems to
affect the problem behavior.

I am using Python 2.2.3 in conjunction with a 3rd party app and do not
have the option of moving to a upgraded/fixed version of Python at this
time. One workaround that I have is to remove the generated Excel 11.0
.py file and no longer use the GetOffset call in my Python code, but
wondered if there is a known fix to the above problem.

Thanks,
Craig 
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to