如何使用python在excel中更改字体大小

我必须创build一个字体为Times New Roman,字体大小为16的内容。如何使用python脚本创build?

我的示例脚本

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

您将字体的高度设置为“缇”,这是一个点的1/20:

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

虽然评论说你是这样做的,但实际上并不适用你定义的风格!
write()调用中使用style关键字:

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

只需添加这个

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