JosephZYU
11/10/2019 - 1:04 PM

color

import xlwings as xw
import numpy as np
import pandas as pd
import datetime as dt
import time
import sys
 
# Fire up a new book in the active Excel instance
wb1 = xw.Book()
# Connects to an unsaved book (looks in all Excel instances)
wb1 = xw.Book('Book1')
sheet = wb1.sheets[0]

# Assign an RGB tuple
sheet.range('A1').color = (0, 255, 0)
sheet.range('A1').color
import xlwings as xw
import numpy as np
import pandas as pd
import datetime as dt
import time
import sys

#* Workaround for missing features: Manipulate the underlying object

wb = xw.Book()
sheet = wb.sheets[0]

# On Windows, the underlying object is a pywin32 COM object
# On Mac, the underlying object is an appscript object

sheet.range('A1').api  # same for the other objects

sheet.range('A10').value = 1
sheet.range('A10').color = (255, 0, 0)

# Code that makes use of the api property will be platform dependent (!)
# clear format, delete format:
if sys.platform.startswith('darwin'):
    # Mac version (appscript syntax)
    sheet.range('A10').api.clear_formats()
elif sys.platform.startswith('win'):
    # Windows version (pywin32 syntax)
    sheet.range('A10').api.ClearFormats()