[python-win32] Controlling Excel via COM: errors with conditional formatting

kurt munson waxingfervor at hotmail.com
Wed Sep 24 14:47:00 CEST 2008


I  have written a Python program to control MS Excel via win32com.client. This allows me to create and control an Excel spreadsheet.I want to use Excel's conditional formatting to color certain cells, but I can't get it to work.Here's the code I use:
 

import win32com.clientxl= win32com.client.Dispatch("Excel.Application")............channamesSheet.Cells(6,3).FormatConditions.Add() Type:=1, Operator:=4, Formula1:="=C5"channamesSheet.Cells(6,3).FormatConditions(1).Interior.ColorIndex = 3I got this code from a record and replay macro in Excel, then swapped out the xl constants for numeric values (1 and 4).This gives me a syntax error when running.I have tried both .Add and .Add(), since sometimes these () are necessary.What am I doing wrong?
_________________________________________________________________
Get more out of the Web. Learn 10 hidden secrets of Windows Live.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20080924/ce11bace/attachment.htm>


More information about the python-win32 mailing list