467,871 Members | 1,744 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,871 developers. It's quick & easy.

win32com.client Excel Color Porblem

Ray
Hi,

I need to use cell's background color.

when I record a macro from excel, it shows:

Rows("7:7").Select
With Selection.Interior
.ColorIndex = 8
.Pattern = xlSolid

how do I run it from python win32com ?
xlApp.ActiveSheet.Rows("7:7").ColorIndex won't work.
Thanks for any Help.
Ray

PS: where or how to find a win32com reference?
May 2 '07 #1
  • viewed: 7024
Share:
2 Replies
ici
On May 3, 1:37 am, Ray <ruil...@earthlink.netwrote:
Hi,

I need to use cell's background color.

when I record a macro from excel, it shows:

Rows("7:7").Select
With Selection.Interior
.ColorIndex = 8
.Pattern = xlSolid

how do I run it from python win32com ?
xlApp.ActiveSheet.Rows("7:7").ColorIndex won't work.

Thanks for any Help.

Ray

PS: where or how to find a win32com reference?
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()

May 2 '07 #2
Ray
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()
May 3 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by RJ | last post: by
1 post views Thread by Patrick | last post: by
reply views Thread by goermezer | last post: by
1 post views Thread by koia | last post: by
2 posts views Thread by ago | last post: by
1 post views Thread by Ransom | last post: by
4 posts views Thread by sterling | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.