[python-win32] Cannot assign values to the Excel Colors property
Graham Bloice
graham.bloice at trihedral.com
Tue Aug 24 20:45:18 CEST 2004
> Graham,
>
> I tried the SetColors(1, xxx) but I get an error message that there is not
> SetColors attribute. I looked for it in my Excel VBA language
> reference and
> couldn't find it there either.
As I (thought I had) explained, the Python COM support doesn't directly
support the VB notion of index properties, i.e. Workbook.Colors(1) =
&H254A70. Colors is a property of the Workbook object that has to be
indexed. The Python COM support turns the property access into a method
access by prepending either Get, for a property read, or Set, for a property
write to the name of the property and passing the index value as a parameter
of the method.
>>> xl = Dispatch("Excel.Application")
>>> xl
<win32com.gen_py.Microsoft Excel 9.0 Object Library._Application instance at
0x23987600>
>>> xl.Visible = -1
>>> wb = xl.Workbooks.Add()
>>> wb
<win32com.gen_py.None.Workbook>
>>> wb.GetColors(2)
16777215.0
>>> wb.SetColors(2, 0)
And sure enough, if I open the Format | Cells | Patterns dialog, the second
color in the palette is black. Note that you can't set the color when the
dialog is open.
Are you sure you've run the MakePy utility on Excel ??
Graham
More information about the Python-win32
mailing list