Andrea Gavana wrote: > Hi Roger, > > On 2/10/07, Roger Upole wrote: >> "Andrea Gavana" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >>> 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]) >> This looks like one of those odd properties that takes parameters. >> There's a method for dynamic dispatches that you can use to >> force it to be treated as a method: >> >> s=win32com.client.dynamic.DumbDispatch(xlsapp.Selection) >> s._FlagAsMethod('Characters') >> s.Characters(200).Insert(finalText[200:400]) >> > > Thank you for your help, it works like a charm! I didn't even know > about "properties that take parameters" :-D >
When you have used MakePy on the type library, things are slightly different for property accessors that take arguments. For those properties that do take arguments MakePy will generate accessors for them as methods, prefixed with "Get" or "Set" as appropriate. If you look in the MakePy generated file for Excel, somewhere in the "class Range()" definition you will find: > # Result is of type Characters > # The method GetCharacters is actually a property, but must be used as > a method to correctly pass the arguments > def GetCharacters(self, Start=defaultNamedOptArg, > Length=defaultNamedOptArg): -- Regards, Graham Bloice _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32