Method
Graphic flipping, also known as image reflection or symmetry transformation, is achieved using the `Flip` method of the `Shape` object. This method flips the graphic around either the horizontal or vertical axis. It has one parameter that specifies whether to flip horizontally or vertically. The corresponding values for horizontal and vertical flips are 0 and 1, respectively.
shp=sht.api.Shapes.AddShape(1, 100, 50, 200, 100) #Rectangular area
shp.Fill.PresetTextured(22) #Preset texture: Walnut wood
shp.Flip(0) #Horizontal flip
shp.Flip(1) #Vertical flip
Sample Code
#Iterating Over Shapes in the Worksheet
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, 50, 50, 200, 100) #Rectangular area
shp2=sht.api.Shapes.AddShape(9, 30, 80, 200, 100) #Elliptical area
shp2.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,0,0))
shp2.Fill.Transparency=0.7
shp3=sht.api.Shapes.AddLine(10,10,200,120) #Line segment
sht.range('F1').value=['Name', 'Type', 'Top-left X', 'Top-left Y', 'Width', 'Height'] # Header
i=0
for shp in sht.api.Shapes: #Iterate through each Shape object in the worksheet
i+=1
sht.api.Cells(i+1, 'F').Value=shp.Name #Output each Shape object's properties
sht.api.Cells(i+1, 'G').Value=shp.Type
sht.api.Cells(i+1, 'H').Value=shp.Left
sht.api.Cells(i+1, 'I').Value=shp.Top
sht.api.Cells(i+1, 'J').Value=shp.Width
sht.api.Cells(i+1, 'K').Value=shp.Height
#bk.save()
#bk.close()
#app.kill()

Leave a Reply