How to change fontsize in excel using python

gmanikandan picture gmanikandan · May 20, 2013 · Viewed 13.5k times · Source

I have to create a content with font as Times New Roman and font size as 16.How to create using python script ?

My sample 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')

Answer

Wooble picture Wooble · May 20, 2013

You set the font's height in "twips", which are 1/20 of a point:

font.height = 320 # 16 * 20, for 16 point