473,850 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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.Workbook s.Add()
sheet = wb.Sheets[0]

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

xlsapp.Selectio n.Characters.Te xt = finalText[0:200]
xlsapp.Selectio n.Characters(20 0).Insert(final Text[200:400])

excelfile = "Hello.xls"
wb.SaveAs(excel file)


And it crashes with an impossible error:

Traceback (most recent call last):
File "D:\MyProjects\ pywin32.py", line 13, in <module>
xlsapp.Selectio n.Characters(20 0).Insert(final Text[200:400])
File "C:\Python25\li b\site-packages\win32c om\client\dynam ic.py", line 172, in
return self._get_good_ object_(self._o leobj_.Invoke(* allArgs),self._ olerepr_.
defaultDispatch Name,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.


"Imaginatio n Is The Only Weapon In The War Against Reality."
Feb 9 '07 #1
0 1582

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

Similar topics

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 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...
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 Python-2.3.4.exe, I next executed: > pywin32-201.win32-py2.3.exe as downloaded from SourceForge, in the belief that it was the appropriate companion for Python-2.3.4 (perhaps this is my mistake?). In both cases, the installed Pythonwin outputs the...
by: Egor Bolonev | last post by:
import os print os.listdir("\\\\delta\\public") outputs and import os print os.listdir("\\\\delta")
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 from the top of my Excel spreadsheet to another location. I would have throught that this should be very straightforward since I've done a fair amount of Excel/Python programming. Unforturnately, I am stuck on this one.
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 win32com.client xl = win32com.client.Dispatch("Excel.Application") xl.Visible = False xl.ScreenUpdating = False
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 3.0, does it means that: - my script using pywin32 for the COM layer and scipy for the maths won't work under 3.0
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?
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, it returns some Mbytes and here is the problem : in the stream of bytes, I randomly losts chunks of ~100bytes.
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 may start application application = Dispatch("Excel.Application") # create new file ('Workbook' in Excel-vocabulary)
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.