473,714 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Exce l.Application")
xl.Visible = False
xl.ScreenUpdati ng = False
wb = xl.Workbooks.Op en("h:\\p.xls" )
sht = wb.Sheets("Shee tName") # 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 3705
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("Exce l.Application")
xl.Visible = False
xl.ScreenUpdati ng = False
wb = xl.Workbooks.Op en("h:\\p.xls" )
sht = wb.Sheets("Shee tName") # 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
5098
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 As Excel.Workbook dim osheets As Excel.Sheets dim result as string
1
7937
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 version of the MS Graph type library. Up until now I have been walking them through the process of setting the references to include their version of MS Graph library. My problem is that I can not seem to get the syntax correct .. or perhaps...
1
3403
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 users use 2000 while the others use 2002. This worked using early binding, but after changing the code to what I thought I needed I have a few errors. Here is the code: Dim xlbook as object Set xlBook = GetObject(, "Excel.Application")...
14
4308
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 hundreds of lines of code to format a Word document in a very specific way. Because my clients have various versions of Word, the problem of broken references comes up. I wish Microsoft had implemented a reasonable solution, so that VBA could do...
8
3854
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 as Object
3
6718
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 xlapp = CreateObject("Excel.Application") and then I went off in debauchery like this:
3
9153
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 on my XP machine without problems. Then, I tried to run the program on a Windows 2000 computer with Office 2000 installed. I got an error: System.IO.FileNotFoundException: File or assembly name "Microsoft.Office.Interop.Excel, or one of its...
11
2739
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? Examples? Thanks
30
2827
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 integer The integers in these arrays are actually pointers to different columns of data in a text file.
0
8711
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9020
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6636
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5948
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4726
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.