473,395 Members | 1,413 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 5847
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
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.