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.
Name | Value | Description |
msoTextOrientationDownward | 3 | Downward |
msoTextOrientationHorizontal | 1 | Horizontal |
msoTextOrientationHorizontalRotatedFarEast | 6 | Horizontal and rotated for East Asian languages support |
msoTextOrientationMixed | -2 | Not supported |
msoTextOrientationUpward | 2 | Upward |
msoTextOrientationVertical | 5 | Vertical |
msoTextOrientationVerticalFarEast | 4 | Vertical 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()
