---------- Forwarded message ----------
From: Andrea Gavana <andrea.gav...@gmail.com>
Date: Sat, Apr 25, 2009 at 2:28 PM
Subject: Re: [python-win32] Formatting parts of an excel cell
To: Mark Tolonen <metolone+gm...@gmail.com>


Hi,

On Sat, Apr 25, 2009 at 2:00 PM, Mark Tolonen wrote:
>
> "Baehr, Manuel" <manuel.ba...@comsoft.aero> wrote in message
> news:737a64deb003704788e5ce515ed146054b6...@csmail.comsoft.de...
>>
>> Hi John,
>>
>>> Check out the thread "Multiple formats in a cell" in this
>>> group around 2009-03-06.
>>
>> thanks for the link! However, I can't use xlwt (and xlrd) because I have
>> to modify an existing excel sheet containing macros. Therefore I used
>> the "win32com" module in python under Windows. This works pretty fine
>> except for my original problem.
>>
>> Any idea how to do it using win32com? So far I only know how to set
>> properties of an entire cell.
>>
>> cell.Font.ColorIndex = 6
>>
>> But as I said, I would like to do it for parts of the text of the cell
>> content.
>>
>> Cheers,
>> Manuel
>
> I recorded an Excel macro to color parts of a cell to find the correct
> syntax.  This should work, but I get an error:
>
>>>> xl.ActiveCell.Characters(1,5).ColorIndex
>
> Traceback (most recent call last):
>  File "<interactive input>", line 1, in <module>
> AttributeError: Characters instance has no __call__ method
>
> The Excel documentation says Characters is a method that should support
> Start and Length parameters.
>
> Anybody know how to call this correctly?

You may try to use the FlagAsMethod method like this:

from win32com.client.dynamic import DumbDispatch

yourCell.Select()

s = DumbDispatch(self.xlsapp.Selection)
s._FlagAsMethod('Characters')
s.Characters(1,5).ColorIndex = whatever

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/



-- 
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to