473,320 Members | 1,841 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,320 software developers and data experts.

[pywin32] - Excel COM problem

Hi All,

I have a very simple python script that tries to put a rectangular
shape in a worksheet and then add some text inside that shape. The
main problem, is that as usual Excel doesn't like input strings longer
than 200 and something characters. So, by just recording a macro in
Excel, I tried to append the text in the shape by dividing it in
chunks. For example, I tried this little script:

#----------------------------------
from win32com.client import Dispatch

finalText = "A"*1250

xlsapp = Dispatch("Excel.Application")
wb = xlsapp.Workbooks.Add()
sheet = wb.Sheets[0]

myShape = sheet.Shapes.AddShape(1, 315, 200, 400, 300)
myShape.Select()

xlsapp.Selection.Characters.Text = finalText[0:200]
xlsapp.Selection.Characters(200).Insert(finalText[200:400])

excelfile = "Hello.xls"
wb.SaveAs(excelfile)
wb.Close()
xlsapp.Quit()

#----------------------------------

And it crashes with an impossible error:

Traceback (most recent call last):
File "D:\MyProjects\pywin32.py", line 13, in <module>
xlsapp.Selection.Characters(200).Insert(finalText[200:400])
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 172, in
__call__
return self._get_good_object_(self._oleobj_.Invoke(*allAr gs),self._olerepr_.
defaultDispatchName,None)
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)

However, the macro I recorded in Excel does exactly that: it appends
chunks of the string with a maximum length of 200 chars.
Am I missing something here?
This is with Python 2.5, PythonWin 2.5 (r25:51908, Sep 19 2006,
09:52:17) [MSC v.1310 32 bit (Intel)] on win32, Windows XP SP2.

Thank you for your consideration.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/
Feb 9 '07 #1
0 1534

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

Similar topics

2
by: Michael Jordan | last post by:
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...
4
by: Bob Chapman | last post by:
On two different Windows 98SE Systems, I have attempted to upgrade working Python 2.3.3 and win32all installations to Python 2.3.4. After what appeared to be successful installations of...
5
by: Egor Bolonev | last post by:
import os print os.listdir("\\\\delta\\public") outputs and import os print os.listdir("\\\\delta")
2
by: John Henry | last post by:
I posted the following message to the Pywin32 list but if anybody here can help, it would be appreciated very much. ============================ Hi list, I have a need to copy 3 rows of data...
2
by: kogrover | last post by:
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...
7
by: vml | last post by:
Hello, I am trying to promote python in my job, my collegue only see matlab and microsoft scripting language. I understood that there willl be no backward compatibility between python 2.x and...
1
by: kernel1983 | last post by:
By reading the doc of pywin32 we can invoke COM like: o = win32com.client.Dispatch("Excel.Application") but is it possible to invoke some GUID directly?
4
by: Xavier | last post by:
Hi, I try to access to a Bluetooth GPS data-logger with Python. I use pySerial. Sending and receiving little messages (~100 char) works fine. However, when I ask the GPS to dump the trails,...
1
by: Ally | last post by:
Hi all, I’m looking to plot charts in Excel from python. After some Googling I’ve found the following code: def plot(x, y, xAxisLog=False, yAxisLog=False): # acquire application object, which...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.