List Info

Thread: Excel COM problem




Excel COM problem
user name
2007-02-08 10:23:24
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:MyProjectspywin32.py", line 13, in
<module>
   
xlsapp.Selection.Characters(200).Insert(finalText[200:400])
  File
"C:Python25libsite-packageswin32comclientdynamic.
py", line 172, in
__call__
    return
self._get_good_object_(self._oleobj_.Invoke(*allArgs),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.v
irgilio.it/infinity77/
_______________________________________________
Python-win32 mailing list
Python-win32python.org

http://mail.python.org/mailman/listinfo/python-win32

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )