473,395 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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(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:
rng1.Count 52 rng2.Count

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
Jul 18 '05 #1
2 5848
jr

"Michael Jordan" <mj*****@adobe.com> wrote in message news:tC*******************@newshog.newsread.com...
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:
rng1.Count 52 rng2.Count

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

Jul 18 '05 #2
Thanks jr! That did the trick, I now get the offset range that I want.
Thanks again for the assistance.

Michael
"jr" <gr******@ix.netcom.com> wrote in message
news:GL***************@newsread1.news.pas.earthlin k.net...

"Michael Jordan" <mj*****@adobe.com> wrote in message

news:tC*******************@newshog.newsread.com...
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:
>> rng1.Count

52
>> rng2.Count

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

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: acharyaks | last post by:
Hi life saver, I am using excel component for the development. The purpose is to connect to excel through the odbc connection string. Then through the connection extract data into a dataset and...
0
by: aaj | last post by:
Hi I use the Excel 10 object library in one of my apps, and to read a range of cells I use : Excel.Range range = worksheet.get_Range(start,end); (System.Array)range.Cells.Value2; to read...
4
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
2
by: George | last post by:
Is there a fast way to transfer an Excel range to an array? Example: Excel range is E2:E300 Dim person() as string Thanks, George
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
6
by: XxLicherxX | last post by:
Hello everyone - new to VB.net working with Excel I am trying to populate data into cells in an Excel spreadsheet using Range.Value. No matter what cell I give as an argument to the Range...
1
by: Robert Bravery | last post by:
HI all, I'm new to C#. I want to open an excel document and work with it in C#. I currently have Excel2000, I think it is version9.0. But Clients might have office XP, XP2003 on Could someone...
0
by: shantanu | last post by:
I am trying to convert a macro code to c# that will copy the values of a column and paste to anather through paste special. Everything is working fine but the transpose meathod to paste the column...
1
by: GuyHarel | last post by:
I am converting a VB6 app to VB.NET The VB6 starts Excel to create a report.On several cells, the VB6 code does this: rg._Default(1, 3).NumberFormat = "0.0000" rg._Default(1, 3) = 140.95...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.