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

标签 python excel xlwt

我必须创建一个字体为 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')

最佳答案

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

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

关于python - 如何使用python更改excel中的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16648134/

相关文章:

excel - 从多个工作表的同一列创建唯一的单词列表,并将其按字母顺序排序到动态命名范围中

需要 VBA 循环逻辑

python - 在 python (xlwt) 中设置 excel 列样式

python - 每次 python 脚本运行时更改 Excel 工作表

python - 在 Spyder 的 IPython 控制台中使用 awk

python - 在python中取消选择所有plotly dash散点图

python - 您如何控制用户对键值数据库中记录的访问?

python - 如果 df1 中的工作表名称与字符串值匹配,我如何将 df2 复制到 df1

Python xlwt 创建错误的 excel 书

python - if else 语句不适用于整数值