pywin32 COM Problem with Excel Range Offset?

M

Michael Jordan

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(xlApp.Cells(8,3),xlApp.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:
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
 
J

jr

Michael Jordan said:
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(xlApp.Cells(8,3),xlApp.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:

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

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

HTH
jr
 
M

Michael Jordan

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

Michael
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top