472,980 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,980 software developers and data experts.

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

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
2 3641
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WZ | last post by:
I used the following code to create a workbook and save it in a webapplication. dim oExcel As Excel.ApplicationClass dim oBook As Excel.WorkbookClass dim obooks As Excel.Workbooks dim designb...
1
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right...
1
by: apgoodb | last post by:
I have a database that I built some functionality to export a query to excel and then do some formatting. After reading a lot of comments it seems I need to use "late binding", because some of the...
14
by: Composer | last post by:
I've read many postings about the problem of Access.References.IsBroken and the consensus seems to be that late binding is the cure-all. I have a very complex Access application that needs...
8
by: deko | last post by:
When using automation (and especially with early binding) I've heard it is best to use explicit references to everything. For example: Dim xlChart as Excel.Chart rather than Dim objChart...
3
by: deko | last post by:
So I've decided to convert from Early Binding to Late Binding. Now that I've been baptized, I need some instruction in the faith. My former ways were thus: Dim xlapp As Excel.Application Set...
3
by: Dent2 | last post by:
I wrote a nice C# excel routine to automate the formatting of some raw CSV data. I wrote the routine on a WinXP computer with Visual Studio .NET 2003 and Office XP installed. It compiled and ran...
11
by: BrianDH | last post by:
Hi Is there a way, in VB.Net, to write a windows based program that will use more than one version of Office (Excel)? Example: if office 2000 then else if office 2003 then. Is this possible? ...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.