XLSXWriter不将格式应用于XLSX文件中的标头行,而不是将格式应用于空单元格
我有一个XLSX文件,对于所有表格,我需要更改标头行的格式以对其应用背景颜色。
但是,当我将fomratting添加到行中时,而不是包含我数据的列,它将应用于所有其他空列。
这是我尝试的:
for sheet_name in xlwriter.sheets:
ws = xlwriter.sheets[sheet_name]
ws.freeze_panes(1, 0) # Freeze the first row.
cell_format = workbook.add_format({'bg_color': 'yellow'})
cell_format.set_bold()
cell_format.set_font_color('red')
cell_format.set_border(1)
ws.set_row(0, cell_format = cell_format)
PS:我尝试了其他问题的解决方案,这些问题是我对这个问题的建议,但这些都不适合我。
I have a xlsx file, for all of its sheet I need to change the formatting of the header row to apply background color to it.
But when I am adding fomratting to the row, instead of the columns which contain my data, it gets applied to all other empty columns.
Here is what I have tried :
for sheet_name in xlwriter.sheets:
ws = xlwriter.sheets[sheet_name]
ws.freeze_panes(1, 0) # Freeze the first row.
cell_format = workbook.add_format({'bg_color': 'yellow'})
cell_format.set_bold()
cell_format.set_font_color('red')
cell_format.set_border(1)
ws.set_row(0, cell_format = cell_format)
P.S : I have tried solution from other question which I was getting as suggestion for this question but none of that works for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最好循环浏览列名并单独编写每个单元格,而不是set_row:
使用Styler有另一个选项,但我认为边框有一个错误。
I think it is better to loop through the column names and write each cell separately, instead of set_row:
There is another option using styler, but I think there's a bug with the border.