[pywin32-bugs] [ pywin32-Bugs-1619086 ] Excel sort fails w/ early binding in Python 2.2.3
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2007-07-28 07:21:17
|
Bugs item #1619086, was opened at 2006-12-20 09:07 Message generated for change (Comment added) made by mhammond You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1619086&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: com Group: None >Status: Closed Resolution: None Priority: 5 Private: No Submitted By: Craig (craigch) Assigned to: Nobody/Anonymous (nobody) Summary: Excel sort fails w/ early binding in Python 2.2.3 Initial Comment: 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-000000000046x0x1x5.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 ---------------------------------------------------------------------- >Comment By: Mark Hammond (mhammond) Date: 2007-07-28 17:21 Message: Logged In: YES user_id=14198 Originator: NO yeah - this sucks :( The problem is that each COM server has different ways of handling default params. MSOffice seems to deal OK with both styles in general, but there are obviously exceptions, as you saw. Since making that change to pywin32 many years ago, the number of complaints about this reduced significantly ---------------------------------------------------------------------- Comment By: Craig (craigch) Date: 2006-12-20 13:07 Message: Logged In: YES user_id=1669630 Originator: YES >> >> rangeToSort.Sort( Key1=sheet.Columns( 3 ), Order1=1 , Header=1, Key2=pythoncom.Missing, Key3=pythoncom.Missing ) >> I ran my test with the 'optional' arguments defined as pythoncom.Missing and it does work now. Previously my code was working under a very old Python 1.5.2 where the 'defaultNamedNotOptArg' was defined as pythoncom.Missing in the .py file generated for the Excel 11.0 Object Library. Evidently the more recent Pywin32 for 2.2.3 has defined these optional arguments as pythoncom.Empty and thus the error was occurring. I expect there was some rationale for changing the defaults, but it seems an 'optional' argument would want to use Missing rather than Empty. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1619086&group_id=78018 |