Use the `AddShape` method of the Shapes object to create rectangles, rounded rectangles, ellipses, and circles.
Name | Value | Description |
msoShapeRectangle | 1 | Rectangle |
msoShapeRoundedRectangle | 5 | Rounded Rectangle |
msoShapeOval | 9 | Ellipse |
Code:
#Drawing Shapes
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
sht.api.Shapes.AddShape(1, 50, 50, 100, 200) #Draw a rectangle face
sht.api.Shapes.AddShape(5, 100, 100, 100, 200) #Draw a rounded rectangle face
sht.api.Shapes.AddShape(9, 150, 150, 100, 200) #Draw an ellipse face
sht.api.Shapes.AddShape(9, 200, 200, 100, 100) #Draw a circle face
shp1=sht.api.Shapes.AddShape(1, 250, 50, 100, 200) #Draw a rectangle
shp2=sht.api.Shapes.AddShape(5, 300, 100, 100, 200) #Draw a rounded rectangle
shp3=sht.api.Shapes.AddShape(9, 350, 150, 100, 200) #Draw an ellipse
shp4=sht.api.Shapes.AddShape(9, 400, 200, 100, 100) #Draw a circle
shp1.Fill.Visible=False
shp2.Fill.Visible=False
shp3.Fill.Visible=False
shp4.Fill.Visible=False
#bk.save()
#bk.close()
#app.kill()
