Method
Use the `TwoColorGradient` method of the `FillFormat` object for two-color gradient fills.
ff.TwoColorGradient(Style, Variant)
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)) #Start color
ff1.TwoColorGradient(3, 1) #Two-color gradient fill
ff1.BackColor.RGB= xw.utils.rgb_to_int((0, 255,0)) #End color
Sample Code
#Area Properties - Multi-color Gradient 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.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.Delete(2)
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)
shp2=sht.api.Shapes.AddShape(9, 400, 50, 200, 100) #Elliptical area
ff2=shp2.Fill
ff2.ForeColor.RGB= xw.utils.rgb_to_int((0,0,255))
ff2.OneColorGradient(7, 1, 1) #One color gradient fill
#Insert color nodes in gradient sequence.
ff2.GradientStops.Insert(xw.utils.rgb_to_int((255,0,0)), 0.25)
ff1.GradientStops.Delete(2)
ff2.GradientStops.Insert(xw.utils.rgb_to_int((0,255,0)), 0.5)
ff2.GradientStops.Insert(xw.utils.rgb_to_int((0,0,255)), 1)
#bk.save()
#bk.close()
#app.kill()

Leave a Reply