How to change fontsize in excel using python

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

My example 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') 
+7
source share
3 answers

You set the font height to "twips", which are 1/20 points:

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

Although the comment says that you do this, you are not actually applying the style that you defined!
Use the style keyword in the write() call:

 worksheet.write(1, 0, label = 'Formatted value', style = style) # Apply the Style 
+1
source

just add this

 style = xlwt.easyxf('font: bold 1,height 280;') 
0
source

All Articles