win32com.client Excel Color Porblem

Discussion in 'Python' started by Ray, May 2, 2007.

  1. Ray

    Ray Guest

    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?
    Ray, May 2, 2007
    #1
    1. Advertising

  2. Ray

    ici Guest

    On May 3, 1:37 am, Ray <> wrote:
    > 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()
    ici, May 3, 2007
    #2
    1. Advertising

  3. Ray

    Ray Guest

    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()
    >
    Ray, May 3, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gandu
    Replies:
    0
    Views:
    1,068
    Gandu
    Jan 8, 2004
  2. Raffounz

    Porblem editing makefile

    Raffounz, Sep 14, 2006, in forum: C++
    Replies:
    1
    Views:
    397
    Victor Bazarov
    Sep 14, 2006
  3. Replies:
    1
    Views:
    291
    Michael Nemtsev [MVP]
    Jan 24, 2009
  4. pp
    Replies:
    7
    Views:
    2,710
    John Machin
    Jan 10, 2010
  5. sed_y
    Replies:
    0
    Views:
    996
    sed_y
    Feb 15, 2012
Loading...

Share This Page