pywin32 COM Problem with Excel Range Offset?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Jordan

    pywin32 COM Problem with Excel Range Offset?

    I'm hoping that someone here can give me some insight into a problem I'm
    running into with Python, pywin32 and Excel. All-in-all using Python and
    pywin32 is great but I've run into a strange problem with the range Offset
    property, I'm not getting the correct offset and the returned range is a
    single cell and not the same size as the original range.

    For example, when I enter the following lines of code in PythonWin :

    from win32com.client import Dispatch
    xlApp = Dispatch('Excel .Application')
    xlApp.Visible = 1
    rng1 = xlApp.Range(xlA pp.Cells(8,3),x lApp.Cells(20,6 ))
    rng1.Select()
    rng2 = rng1.Offset(2,2 )
    rng2.Select()

    rng1 correctly defines and selects cells C8:F20 but rng2 is incorrectly
    defined as D9 instead of E10:H22.

    Digging a little further if I look at the cell sizes for the two ranges I
    get the following:
    [color=blue][color=green][color=darkred]
    >>> rng1.Count[/color][/color][/color]
    52[color=blue][color=green][color=darkred]
    >>> rng2.Count[/color][/color][/color]
    1

    What's going on with the Offset property? If I enter the equivalent VBA code
    into the Immediate window from the Visaul Basic Editor within Excel I get
    the correct behavior. Is this a pywin32 bug?

    My configuration:
    pywin32 (build 200) {I got the lastest version to see if this would fix
    the problem - it didn't}
    Python 2.3.3
    MS Excel 2002
    Windows XP

    Any insight into this problem will be greatly appreciated.

    Michael


  • jr

    #2
    Re: pywin32 COM Problem with Excel Range Offset?


    "Michael Jordan" <mjordan@adobe. com> wrote in message news:tCeWb.1421 $VP1.966333@new shog.newsread.c om...[color=blue]
    > I'm hoping that someone here can give me some insight into a problem I'm
    > running into with Python, pywin32 and Excel. All-in-all using Python and
    > pywin32 is great but I've run into a strange problem with the range Offset
    > property, I'm not getting the correct offset and the returned range is a
    > single cell and not the same size as the original range.
    >
    > For example, when I enter the following lines of code in PythonWin :
    >
    > from win32com.client import Dispatch
    > xlApp = Dispatch('Excel .Application')
    > xlApp.Visible = 1
    > rng1 = xlApp.Range(xlA pp.Cells(8,3),x lApp.Cells(20,6 ))
    > rng1.Select()
    > rng2 = rng1.Offset(2,2 )
    > rng2.Select()
    >
    > rng1 correctly defines and selects cells C8:F20 but rng2 is incorrectly
    > defined as D9 instead of E10:H22.
    >
    > Digging a little further if I look at the cell sizes for the two ranges I
    > get the following:
    >[color=green][color=darkred]
    > >>> rng1.Count[/color][/color]
    > 52[color=green][color=darkred]
    > >>> rng2.Count[/color][/color]
    > 1
    >
    > What's going on with the Offset property? If I enter the equivalent VBA code
    > into the Immediate window from the Visaul Basic Editor within Excel I get
    > the correct behavior. Is this a pywin32 bug?
    >
    > My configuration:
    > pywin32 (build 200) {I got the lastest version to see if this would fix
    > the problem - it didn't}
    > Python 2.3.3
    > MS Excel 2002
    > Windows XP
    >
    > Any insight into this problem will be greatly appreciated.
    >
    > Michael
    >
    >[/color]

    Use: GetOffset(2, 2) instead.
    For some reason gen.py changes "Offset()" to
    "GetOffset( )"

    HTH
    jr



    Comment

    • Michael Jordan

      #3
      Re: pywin32 COM Problem with Excel Range Offset?

      Thanks jr! That did the trick, I now get the offset range that I want.
      Thanks again for the assistance.

      Michael


      "jr" <grreeder@ix.ne tcom.com> wrote in message
      news:GLtWb.263$ tL3.182@newsrea d1.news.pas.ear thlink.net...[color=blue]
      >
      > "Michael Jordan" <mjordan@adobe. com> wrote in message[/color]
      news:tCeWb.1421 $VP1.966333@new shog.newsread.c om...[color=blue][color=green]
      > > I'm hoping that someone here can give me some insight into a problem I'm
      > > running into with Python, pywin32 and Excel. All-in-all using Python and
      > > pywin32 is great but I've run into a strange problem with the range[/color][/color]
      Offset[color=blue][color=green]
      > > property, I'm not getting the correct offset and the returned range is a
      > > single cell and not the same size as the original range.
      > >
      > > For example, when I enter the following lines of code in PythonWin :
      > >
      > > from win32com.client import Dispatch
      > > xlApp = Dispatch('Excel .Application')
      > > xlApp.Visible = 1
      > > rng1 = xlApp.Range(xlA pp.Cells(8,3),x lApp.Cells(20,6 ))
      > > rng1.Select()
      > > rng2 = rng1.Offset(2,2 )
      > > rng2.Select()
      > >
      > > rng1 correctly defines and selects cells C8:F20 but rng2 is incorrectly
      > > defined as D9 instead of E10:H22.
      > >
      > > Digging a little further if I look at the cell sizes for the two ranges[/color][/color]
      I[color=blue][color=green]
      > > get the following:
      > >[color=darkred]
      > > >>> rng1.Count[/color]
      > > 52[color=darkred]
      > > >>> rng2.Count[/color]
      > > 1
      > >
      > > What's going on with the Offset property? If I enter the equivalent VBA[/color][/color]
      code[color=blue][color=green]
      > > into the Immediate window from the Visaul Basic Editor within Excel I[/color][/color]
      get[color=blue][color=green]
      > > the correct behavior. Is this a pywin32 bug?
      > >
      > > My configuration:
      > > pywin32 (build 200) {I got the lastest version to see if this would[/color][/color]
      fix[color=blue][color=green]
      > > the problem - it didn't}
      > > Python 2.3.3
      > > MS Excel 2002
      > > Windows XP
      > >
      > > Any insight into this problem will be greatly appreciated.
      > >
      > > Michael
      > >
      > >[/color]
      >
      > Use: GetOffset(2, 2) instead.
      > For some reason gen.py changes "Offset()" to
      > "GetOffset( )"
      >
      > HTH
      > jr
      >
      >
      >[/color]


      Comment

      Working...