By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,996 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,996 IT Pros & Developers. It's quick & easy.

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

P: n/a
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...

Oct 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ko******@gmail.com schrieb:
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

Oct 19 '06 #2

P: n/a

On Oct 19, 10:09 am, Thomas Heller <thel...@ctypes.orgwrote:
Thomas- Hide quoted text -- Show quoted text -
That's it thanks. A quick google search lead me to:

http://www.py2exe.org/index.cgi/IncludingTypelibs

Cheers

- Kevin

Oct 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.