How To Set Text Properties Using xlwings?

Method

In Excel, fonts are represented by the `Font` object. When setting the font, it is usually done by obtaining the `Font` object through a property, and then using the properties and methods of the object for configuration.

 

The main properties of the `Font` object include: 

– Bold: Whether the font is bold. `True` for bold, `False` for not bold.

– Color: RGB color shading.

– ColorIndex: Index coloring. The index number of a color in the color lookup table.

– FontStyle: Font style, such as “Bold Italic”.

– Italic: Whether the font is italicized. `True` for italicized, `False` for not italicized.

– Name: Font name.

– Size: Font size.

– Strikethrough: Whether to apply a strikethrough. `True` to apply, `False` to not apply.

– Subscript: Whether the text is set as subscript. `True` to apply, `False` to not apply.

– Superscript: Whether the text is set as superscript. `True` to apply, `False` to not apply.

– ThemeColor: Theme color shading.

– ThemeFont: Theme font.

– TintAndShade: Darken or lighten the font color, with a value between -1 (darkest) to 1 (lightest).

– Underline: The type of underline. 

  – Value -4142: No underline 

  – Value 2: Single underline 

  – Value -4119: Bold double underline 

  – Value 5: Close together thin double underline

 

sht.api.Range(‘C3′).Value=’Font Test123’

ft=sht.api.Range(‘C3’).Font

ft.Name = ‘Times New Roman’

ft.ColorIndex = 3

ft.Size = 20

ft.Bold=True

ft.Strikethrough = False

ft.Underline = 5

ft.Italic=True

Sample Code

#Translation transformation

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.AddShape(1, 100, 50, 200, 100)    #Rectangular area
shp.Fill.PresetTextured(5)    #Preset texture: Water drop
shp.IncrementLeft(70)    #Move right by 70 units
shp.IncrementTop(50)    #Move down by 50 units

#bk.save()
#bk.close()
#app.kill()
Set Text Properties Using xlwings
February 27, 2026 (0)


Leave a Reply

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