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/

相关文章:

python - 使用 Python 发送推特转推

python - 从 2 级嵌套字典中过滤内部键

python - 安装涉及解析要求的 Tweepy 错误

excel - Excel 的 MATCH 和 TIME 公式问题

python - Eclipse XLRD、XLWT 导入错误

Python 到 cython - 提高大型数组迭代的性能

excel - 从另一个范围中的值定义一个范围

excel - 具有 1 个条目的数组循环

python - 如何使用 python xlrd 从 excel 工作表中检索图像

xlwt - 始终显示小数点后 4 位