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

Discussion in 'Python' started by kogrover@gmail.com, Oct 19, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Re: pywin32 COM sort in Excel (late binding fails, early bindingworks) (+py2exe)

    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
    Thomas Heller, Oct 19, 2006
    #2
    1. Advertising

  3. Kevin Grover Guest

    Kevin Grover, Oct 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shaun.86

    early vs late binding

    shaun.86, Dec 19, 2005, in forum: Java
    Replies:
    2
    Views:
    16,474
  2. Stu
    Replies:
    1
    Views:
    582
    Arne Adams
    Dec 18, 2004
  3. Olaf Meding

    MS COM early and late binding

    Olaf Meding, Apr 27, 2004, in forum: Python
    Replies:
    4
    Views:
    392
    Simon Brunning
    Apr 28, 2004
  4. F. GEIGER
    Replies:
    3
    Views:
    756
    F. GEIGER
    Aug 6, 2004
  5. RN1

    Late & Early Binding

    RN1, Mar 18, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    593
    Anthony Jones
    Mar 19, 2008
Loading...

Share This Page