python - 如何使用 Python/XlsxWriter 将单个单元格设置为数字和粗体格式

标签 python xlsxwriter

我已将列格式设置为非粗体数字。我希望仅将该列的总值(value)/单元格格式化为数字并加粗

下面的代码将整个列格式化为数字(这很好),但也将整个列加粗,但只希望列的最后一个单元格加粗。尝试了多种方法来实现此目的,但语法上均不允许。例如:没有“worksheet1.set_cell”

# Set format for accounting
Acct = workbook.add_format()
Acct.set_num_format(0x2c)
worksheet1.set_column('N:N', 12, Acct) 

AcctBold = workbook.add_format({'num_format': 0x2c, 'bold': True})
worksheet1.set_column('N200:N200', 12, AcctBold) #bolds the entire column

目标:N 列的最后一个单元格格式为会计格式并加粗。该列的其余部分未加粗

最佳答案

set_column()方法设置整个列的属性。如果要为单元格设置数据,请使用 write() :

worksheet1.write('N200', 12, AcctBold)

关于python - 如何使用 Python/XlsxWriter 将单个单元格设置为数字和粗体格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56464646/

相关文章:

python - 如何使用 XlsxWriter 自动定义 excel 工作表名称?

python - 在python中按特定年份分组数据

python - 列出图像路径 - 'Namespace' 对象没有属性 '__getitem__'

python - iPython 文件路径自动补全

python - 如何将 pandas df 保存到 Excel 工作表然后对其进行格式化?

python-3.x - 在 xlsxwriter 中以可读的方式缩放图像

Python xlsxwriter TypeError : tuple indices must be integers, 不是 str

python字典在范围内 float 搜索

python - PyQt:自定义属性的 QDataWidgetMapper 映射

python - 使用方法/函数格式化 xlsx writer