Method
#xlwings API
sht.api.Range(‘A1:E1’).Font.Name = ‘Arial’ #Set the font to Arial
sht.api.Range(‘A1:E1’).Font.ColorIndex = 3 #Set the font color to red
sht.api.Range(‘A1:E1’).Font.Size = 20 #Set the font size to 20
sht.api.Range(‘A1:E1’).Font.Bold = True #Set the font to bold
sht.api.Range(‘A1:E1’).Font.Italic = True #Set the font to italic
sht.api.Range(‘A1:E1’).Font.Underline=xw.constants.UnderlineStyle.xlUnderlineStyleDouble #Add a double underline to the text
sht.api.Range(‘C1′).Value=’Test123’
sht.api.Range(‘A3:E3’).Font.Color =xw.utils.rgb_to_int((0, 0, 255))
#sht.api.Range(‘A3:E3’).Font.Color =16711680 # or 0x0000FF
#sht.api.Range(‘A1:E1’).Font.ColorIndex = 3
#sht.api.Range(‘A3:E3’).Font.ThemeColor =5
sht.api.Range(‘C3′).Value=’Test456’
Sample Code
#Cell Font Styles
import xlwings as xw #Import the xlwings package
app=xw.App()
bk=app.books.active #Get the active workbook
sht=bk.sheets.active #Get the active worksheet
#xlwings API
sht.api.Range('A1:E1').Font.Name = 'Arial' #Set the font to Arial
sht.api.Range('A1:E1').Font.ColorIndex = 3 #Set the font color to red
sht.api.Range('A1:E1').Font.Size = 20 #Set the font size to 20
sht.api.Range('A1:E1').Font.Bold = True #Set the font to bold
sht.api.Range('A1:E1').Font.Italic = True #Set the font to italic
sht.api.Range('A1:E1').Font.Underline=xw.constants.UnderlineStyle.xlUnderlineStyleDouble #Add a double underline to the text
sht.api.Range('C1').Value='Test123'
sht.api.Range('A3:E3').Font.Color =xw.utils.rgb_to_int((0, 0, 255))
#sht.api.Range('A3:E3').Font.Color =16711680 # 或0x0000FF
#sht.api.Range('A1:E1').Font.ColorIndex = 3
#sht.api.Range('A3:E3').Font.ThemeColor =5
sht.api.Range('C3').Value='Test456'
#bk.close()
#app.kill()

Leave a Reply