xlwings: Shapes: Rectangles, Rounded Rectangles, Ellipses, and Circles

Use the `AddShape` method of the Shapes object to create rectangles, rounded rectangles, ellipses, and circles.

NameValueDescription
msoShapeRectangle1Rectangle
msoShapeRoundedRectangle5Rounded Rectangle
msoShapeOval9Ellipse

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()


category : xlwings: Shapes

Leave a Reply

Your email address will not be published. Required fields are marked *

Zoomed Image