How To Set Cell Background Color Using xlwings?

Method

#xlwings

sht.range(‘A1:E1’).color=(210, 67, 9)

#sht[‘A:A, B2, C5, D7:E9’].color=(100,200,150)

 

#xlwings API

#sht.api.Range(‘A1:E1’).Interior.Color=xw.utils.rgb_to_int((0, 255, 0))

#sht.api.Range(‘A1:E1’).Interior.Color=65280

#sht.api.Range(‘A1:E1’).Interior.ColorIndex=6

#sht.api.Range(‘A1:E1’).Interior.ThemeColor=5

Sample Code

#Background color of the cell

import xlwings as xw    #Import the xlwings package

app=xw.App()
bk=app.books.active    #Get the active workbook
sht=bk.sheets.active    #Get the active worksheet

#xlwings
#sht.range('A1:E1').color=(210, 67, 9)
sht['A:A, B2, C5, D7:E9'].color=(100,200,150)

#xlwings API
#sht.api.Range('A1:E1').Interior.Color=xw.utils.rgb_to_int((0, 255, 0))
#sht.api.Range('A1:E1').Interior.Color=65280
#sht.api.Range('A1:E1').Interior.ColorIndex=6
#sht.api.Range('A1:E1').Interior.ThemeColor=5

#bk.close()
#app.kill()
Set Cell Background Color Using xlwings
February 7, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *