I have to create a content with font as Times New Roman and font size as 16.How to create using python script ?
import xlwt
workbook = xlwt.Workbook(encoding = 'ascii')
worksheet = workbook.add_sheet('My Worksheet')
font = xlwt.Font() # Create the Font
font.name = 'Times New Roman'
style = xlwt.XFStyle() # Create the Style
style.font = font # Apply the Font to the Style
worksheet.write(0, 0, label = 'Unformatted value')
worksheet.write(1, 0, label = 'Formatted value') # Apply the Style to the Cell
workbook.save('fontxl.xls')
work_sheet_a1. font = Font(size=23, underline='single', color='FFBB00', bold=True, italic=True) #We apply the following parameters to the text: size - 23, underline, color = FFBB00 (text color is specified in RGB), bold, oblique. If we do not need a bold font, we use the construction: bold = False.
How do you bold and italicize in Python? To make text bold and italic, you can enclose the text in the escape sequence '\033[1;3m' and '\033[0m'.
You set the font's height in "twips", which are 1/20 of a point:
font.height = 320 # 16 * 20, for 16 point
Although the comment says that you do, you don't actually apply the style you defined!
Use the style
keyword in the write()
call:
worksheet.write(1, 0, label = 'Formatted value', style = style) # Apply the Style
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With