xlwings: Shapes: Labels

Use the `AddLabel` method of the `Shapes` object to create a label. The syntax is: 

sht.api.Shapes.AddLabel(Orientation,Left,Top,Width,Height)

Where `sht` represents a worksheet object. This method returns a `Shape` object that represents the label.

NameValueDescription
msoTextOrientationDownward3Downward
msoTextOrientationHorizontal1Horizontal
msoTextOrientationHorizontalRotatedFarEast6Horizontal and rotated for East Asian languages support
msoTextOrientationMixed-2Not supported
msoTextOrientationUpward2Upward
msoTextOrientationVertical5Vertical
msoTextOrientationVerticalFarEast4Vertical for East Asian languages support

shp=sht.api.Shapes.AddLabel(1,100,20,60,150)    #Add labels

shp.TextFrame2.TextRange.Characters.Text =’Test Python Label’    #Label text

Code:

#Drawing Labels

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.AddLabel(1,100,20,60,150)    #Add labels
shp.TextFrame2.TextRange.Characters.Text ='Test Python Label'    #Label text

#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