我必须创建一个内容,字体为Times New Roman,字体大小为16.如何使用python脚本创建?
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')
Run Code Online (Sandbox Code Playgroud)
Woo*_*ble 14
您可以在"twips"中设置字体的高度,这是一个点的1/20:
font.height = 320 # 16 * 20, for 16 point
Run Code Online (Sandbox Code Playgroud)
尽管评论说您这样做,但您实际上并没有应用您定义的样式!在调用中
使用关键字:stylewrite()
worksheet.write(1, 0, label = 'Formatted value', style = style) # Apply the Style
Run Code Online (Sandbox Code Playgroud)