win32com.client Excel Color Porblem

Ray ruiligc at earthlink.net
Thu May 3 07:42:33 EDT 2007


Thanks a lot!!


ici wrote:
> My Excel Template :) + Rows
> 
> # -*- encoding:utf-8 -*-
> import win32com.client
> 
> try: import psyco; psyco.full()
> except ImportError: pass
> 
> try:
>     app = win32com.client.Dispatch("Excel.Application.11") # Excel
> 2003
> except com_error:
>     try:
>         app = win32com.client.Dispatch("Excel.Application.10") # Excel
> XP
>     except com_error:
>         try:
>             app = win32com.client.Dispatch("Excel.Application.9") #
> Excel 2000
>         except com_error:
>             try:
>                 app = win32com.client.Dispatch("Excel.Application.8")
> # Excel 97
>             except com_error:
>                 app = win32com.client.Dispatch("Excel.Application") #
> Excel 5.0?
>                 # Or raise "No Office ..."
> 
> app.Visible = True
> wbk = app.Workbooks.Add()
> app.DisplayAlerts = False
> while wbk.Worksheets.Count > 1:
>     wbk.Worksheets[0].Delete()
> wbk.Worksheets[0].Name = "SHIT"
> sht = wbk.Worksheets[0] # Containers starts with 0!
> sht.Name += "$"
> 
> # Rows
> rng = sht.Rows(7)
> rng.Interior.ColorIndex = 6
> sht.Rows(8).Interior.ColorIndex = 8
> # Rows End
> 
> app.DisplayAlerts = True
> wbk.SaveAs(r"c:\temp\test.xls")
> app.Quit()
> 



More information about the Python-list mailing list