[Tutor] CellColor in excel

Adam Groszer adamg@mailbox.hu
Wed Jun 4 11:58:02 2003


>From VBA it works like this:

Worksheets("Sheet1").Cells(10, 10).Interior.ColorIndex =3D 3

(just checked)

Adam

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
janos.juhasz@VELUX.com
Sent: Wednesday, 2003 June 04. 5:42 PM
To: tutor@python.org
Subject: [Tutor] CellColor in excel


Hy All,

can someone show me, how the backgroud color of a cell in MS Excel can be
set to RED.

I copied a simple module from the book  'Programming on win32', written b=
y
Mark Hammond & Andy Robinson. It is a very nice and usefull book.

import win32com.client

class easyExcel:
      def __init__(self, filename=3DNone):
            """Megnyitja az excel f=E1jlt."""
            self.xlApp =3D win32com.client.Dispatch('Excel.Application')
            self.filename =3D filename
            self.xlBook =3D self.xlApp.Workbooks.Open(filename)

      def save(self, newfilename=3DNone):
            if filename:
                  self.filename =3D newfilename
                  self.xlApp.SaveAs(self.filename)
            else:
                  self.xlApp.Save()

      def close(self):
            self.xlBook.Close(SaveChanges=3D0)
            del self.xlApp

      def GetCell(self, sheet, row, col):
            sht =3D self.xlApp.WorkSheets(sheet)
            return sht.Cells(row, col).Value


      def SetRed(self, sheet, row, col):
            sht =3D self.xlApp.WorkSheets(sheet)
            sht.Cells(row, col).ColorIndex =3D 3

But the SetRed function wouldn't like to work :(
I know I had seen example for this, but I did't know where.

Best regards,
-----------------------
Juh=E1sz J=E1nos
IT department

VELUX Magyarorsz=E1g
Fert=F5di =C9p=EDt=F5komponens Kft.
Fert=F5d Malom k=F6z 1.
Phone: +36 99 537 939
Fax: +36 99 537 921
E-Mail: janos.juhasz@VELUX.com



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor