Method
Use the `Patterned` method of the `FillFormat` object to apply pattern fill. This method takes an `MsoPatternType` enumeration value, which specifies the pattern to be used.
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))
Sample Code
#Area properties - Picture 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.UserPicture(r"D:\picpy.jpg") #Picture fill
shp2=sht.api.Shapes.AddShape(9, 400, 50, 200, 100) #Elliptical area
ff2=shp2.Fill
ff2.UserPicture(r"D:\picpy.jpg") #Picture fill
#bk.save()
#bk.close()
#app.kill()

Leave a Reply