Method
shp1=sht.api.Shapes.AddShape(1, 100, 50, 200, 100) #Rectangular area
ff1=shp1.Fill
ff1.ForeColor.RGB= xw.utils.rgb_to_int((255,0,0))
ff1.OneColorGradient(3, 1, 1) #One color gradient fill
#Insert color nodes in gradient sequence.
ff1.GradientStops.Insert(xw.utils.rgb_to_int((255,0,0)), 0.25)
ff1.GradientStops.Insert(xw.utils.rgb_to_int((0,255,0)), 0.5)
ff1.GradientStops.Insert(xw.utils.rgb_to_int((0,0,255)), 1)
Sample Code
#Area Properties - Pattern Fill
import xlwings as xw #Import xlwings package
app=xw.App()
bk=app.books.active #Get the active workbook
sht=bk.sheets.active #Get the active worksheet
shp1=sht.api.Shapes.AddShape(1, 100, 50, 200, 100) #Rectangular area
ff1=shp1.Fill
ff1.ForeColor.RGB= xw.utils.rgb_to_int((255,0,0))
ff1.Patterned(22) #Pattern fill
ff1.BackColor.RGB= xw.utils.rgb_to_int((0,255,0))
shp2=sht.api.Shapes.AddShape(9, 400, 50, 200, 100) #Elliptical area
ff2=shp2.Fill
ff2.ForeColor.RGB= xw.utils.rgb_to_int((255,255,0))
ff2.Patterned(48) #Pattern fill
ff2.BackColor.RGB= xw.utils.rgb_to_int((0,0,255))
#bk.save()
#bk.close()
#app.kill()

Leave a Reply