Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > pywin32 COM sort in Excel (late binding fails, early binding works) (+py2exe)

Reply
Thread Tools

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

 
 
kogrover@gmail.com
Guest
Posts: n/a
 
      10-19-2006
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...

 
Reply With Quote
 
 
 
 
Thomas Heller
Guest
Posts: n/a
 
      10-19-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Kevin Grover
Guest
Posts: n/a
 
      10-20-2006

On Oct 19, 10:09 am, Thomas Heller <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Pywin32: How to import data into Excel? Simon Brunning Python 1 11-13-2005 06:11 PM
RE: Pywin32: How to import data into Excel? Tim Golden Python 0 11-08-2005 01:28 PM
RE: Pywin32: How to import data into Excel? Tim Golden Python 1 11-08-2005 12:59 PM
pywin32 COM Problem with Excel Range Offset? Michael Jordan Python 2 02-12-2004 07:06 PM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments