473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
2 9085
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: RJ | last post by:
Hi, I've been going over the Quick Start to Client side COM and Python and many other sources, but cannot find an example that will get my com/ActiveX .ocx USB device driver imported. The Excel...
1
by: Patrick | last post by:
I am investigating a web-based app wherein I wanted to provide html form frontends to an Excel spreadsheet sitting on a MS Windows server; with each authenticated HTTP user having thier own...
0
by: goermezer | last post by:
Hello, I have some problems to automate a CAD (computer aided design) Software called CATIA V5 from Dassault Systemes. CATIA V5 has a builtin VB-Editor like Word, Excel, … and registers itself...
1
by: koia | last post by:
Hi, I have a problem with adding attributes to a Line in an Excel drawing using the Python win32com interface. From recording in Excel I get the Macro: Sub Makro1()...
2
by: ago | last post by:
I am trying to make the win32com HelloWorld server work with a VBA client but I get: Run-time error '-2147467259(80004005)': Automation error Unspecified error I googled for the error but...
1
by: Ransom | last post by:
Hey folks... Newbie here. I'm working with win32com launching, closing and re-launching Excel grabbing output and doing stuff. Well, on some occasions, I get the following error: ...
4
by: vithi | last post by:
Hi' I am trying to launch an application. When I try like that When I try like that Excel is opening import win32com.client object = win32com.client.Dispatch("Excel.Application") object.Visible...
1
by: SPJ | last post by:
Sorry, forgot to mention Subject in my earlier post, hence reposting. ------------ I am writing a script which need's to convert an excel file to csv (text) format. For that I am using the...
4
by: sterling | last post by:
I'm curious as to why the difference between IDLE and pythonWin when using win32com. opening an excel file, i've attempted to grab the chart information out of the file. commands like co =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.