xlwings: Shapes: Line Segments

Use the AddLine method of the Shapes object to create a line segment. The method syntax is:

sht.api.Shapes.AddLine(BeginX, BeginY, EndX, EndY)

Where sht refers to a worksheet object. The parameters BeginX, BeginY represent the coordinates of the starting point, and EndX, EndY represent the coordinates of the endpoint. This method returns a Shape object representing the line segment.

Code:

#Drawing Line Segments

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

shp=sht.api.Shapes.AddLine(10,10,250,250)    #Create a line segment `Shape` object
ln=shp.Line    #Get the line shape object
#Set properties of the line shape object: line style, color, and width
ln.DashStyle=3
ln.ForeColor.RGB=xw.utils.rgb_to_int((255, 0, 0))
ln.Weight=5

#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