pywin32 COM sort in Excel (late binding fails, early binding works) (+py2exe)

K

kogrover

ISSUE: COM Excel Sort works with Early Binding, but not Late Binding,
but py2exe only does Late Binding

I have code similar to this (type from notes, so there may be a
typo...)

import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = False
xl.ScreenUpdating = False
wb = xl.Workbooks.Open("h:\\p.xls")
sht = wb.Sheets("SheetName") # wb.Worksheets("Sheetname")
sht.Cells.Sort(Key1=sht.Cells(2,1), Order1=1, Header=1, Orientation=1)

Python: 2.4.3
pywin32 200
py2exe 0.6.5
Office 2000

The sort DOES NOT work if called from a normal install (e.g. using late
binding): the Header line gets sorted with all the data.

ID Value Mort
232 2 54
54 33 232
--->
54 33 232
232 2 54
ID Value Mort


HOWEVER, If I run

makepy.py and select the "Microsoft Excel 9.0" (--> I'm typing this
from memory!)
and run it, it creates the GUID'd py file in gen_py

If I run the above code again (on a clean copy of the xls file), it
DOES sort the sheet correctly --- the header line is left alone.

ID Value Mort
232 2 54
54 33 232
--->
ID Value Mort
54 33 232
232 2 54

Normally, this would not be an issue, but when I bundle my app using
py2exe it does not grab the gen_py stuff.

Any help appreciated...
 
T

Thomas Heller

ISSUE: COM Excel Sort works with Early Binding, but not Late Binding,
but py2exe only does Late Binding

I have code similar to this (type from notes, so there may be a
typo...)

import win32com.client
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = False
xl.ScreenUpdating = False
wb = xl.Workbooks.Open("h:\\p.xls")
sht = wb.Sheets("SheetName") # wb.Worksheets("Sheetname")
sht.Cells.Sort(Key1=sht.Cells(2,1), Order1=1, Header=1, Orientation=1)

Python: 2.4.3
pywin32 200
py2exe 0.6.5
Office 2000

The sort DOES NOT work if called from a normal install (e.g. using late
binding): the Header line gets sorted with all the data.

ID Value Mort
232 2 54
54 33 232
--->
54 33 232
232 2 54
ID Value Mort


HOWEVER, If I run

makepy.py and select the "Microsoft Excel 9.0" (--> I'm typing this
from memory!)
and run it, it creates the GUID'd py file in gen_py

If I run the above code again (on a clean copy of the xls file), it
DOES sort the sheet correctly --- the header line is left alone.

ID Value Mort
232 2 54
54 33 232
--->
ID Value Mort
54 33 232
232 2 54

Normally, this would not be an issue, but when I bundle my app using
py2exe it does not grab the gen_py stuff.

Any help appreciated...
You must instruct py2exe to pick up the typelib wrappers, this does
not happen automatically. IIRC, there's a sample in the distribution
somewhere.

Thomas
 

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top